External CSS in Flying Saucer

I would like to know how to enable external CSS in Flying-Saucer. Before THB I checked with all available links in StackOverflow, but they do not help. That is why I did it myself.

TestCSS.xhtmlrenamed version TestCSS.html. Therefore, their contents are the same. Below (Image 1) is the structure of my project in the Eclipse IDE. If I run TestCSS.html, it will give the page result as image 2 in the browser.

Below is the code that does not work as external CSS:

This one Working :
<style>
.redFontClass
{
  color : red;
}
.blueFontClass
{
  color : blue;
}
</style>

This one NOT Working :
<link href="RedCSS.css" rel="stylesheet" type="text/css" />

This one NOT Working :
<link rel="stylesheet" 
href="http://localhost:8888/Fly-Sauccer-Web/css/RedCSS.css" type="text/css" />

This one NOT Working :
<link href="file:///C:/Users/Joseph.M/WorkPlace_Struts2/Fly-Sauccer-Web/WebContent/css/RedCSS.css"  rel="stylesheet" type="text/css" />

I tried all the paths, including the absolute css path inside xhtml. In addition, css is not applicable. Please help me fix this problem.

Image 1

enter image description here

Image 2

enter image description here

RedCSS.css

.fontClass
{
  color : red;
}

TestCSS.html

<html>
<head>
<link href="file:///C:/Users/Joseph.M/WorkPlace_Struts2/Fly-Sauccer-Web/WebContent/css/RedCSS.css"  rel="stylesheet" type="text/css" />
</head>
<body>
<b>This Should come assss <span class = "fontClass" >Red</span> </b>
</body>
</html>

Java Code:

public static void main(String[] args) throws Exception{

    // Path of Input File 
    String inputFile = "C:\\Users\\Joseph.M\\WorkPlace_Struts2\\Fly-Sauccer-Web\\WebContent\\TestCSS.xhtml";
    // Path of Output File 
    String outputFile = "C:\\Users\\Joseph.M\\WorkPlace_Struts2\\Fly-Sauccer-Web\\output.pdf";
    OutputStream os = new FileOutputStream(outputFile);             
    ITextRenderer renderer = new ITextRenderer();

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputStream is = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File(inputFile)));
    Document doc = builder.parse(is);
    is.close();
    renderer.setDocument(doc,null);        
    renderer.layout();
    renderer.createPDF(os);             
    os.close();
}
+4
2

, <link href="css/RedCSS.css" rel="stylesheet" type="text/css" /> .

:

:

enter image description here

1: testRed.html

<html>
<head>
    <link href="css/testRed.css" rel="stylesheet" type="text/css" />
</head>
<body>
    Should be <b class="redFontClass">red</b>
</body>
</html>

2: css/testRed.css

.redFontClass {color : red;}

Java:

  String inputFile = "testRed.html";
  String outputFile = "testRed.pdf";
  OutputStream os = new FileOutputStream(outputFile);
  ITextRenderer renderer = new ITextRenderer();

  DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  InputStream is = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File(inputFile)));
  Document doc = builder.parse(is);
  is.close();
  renderer.setDocument(doc, null);
  renderer.layout();
  renderer.createPDF(os);
  os.close();
0

, obourgain <link href="css/testRed.css" rel="stylesheet" type="text/css" /> > 302, , , get . a/before css, . <link href="/css/testRed.css" rel="stylesheet" type="text/css" /> >

0

All Articles