emichelli / flying-saucer

Automatically exported from code.google.com/p/flying-saucer
0 stars 0 forks source link

CSS not being applied to generated PDF #261

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
<b>Problem</b>

I use Flying-saucer to generate a PDF from an HTML file.

The PDF is correctly generated but the CSS is not applied to it.

<b>HTML</b>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
  <link rel="stylesheet" media="print" type="text/css" href="C:/Users/f_antbar/Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Gest_saisie/css/printPDF.css"/>
</head>
<body>
  <div style="background-color:white; width:100%"><img src="C:/Users/f_antbar/Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Gest_saisie/img/logo_50.jpg"/></div>
  <div id="corps">...

<b>Generator</b>

try {
    FileOutputStream os = new FileOutputStream(context.getRealPath("documents")+"/print/test.pdf");
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(new File(context.getRealPath("documents")+"/print/test.html"));
    renderer.layout();
    renderer.createPDF(os);
    os.close();
    System.out.println("PDF created");
} catch (Exception ex) {
     ex.printStackTrace();
}

The CSS is validated by the W3C validator, the path is correct since I used it 
with only iText but since iText doesn't support much CSS I wanted to try with 
flying-saucer.

<b>Configuration</b>

I'm working with

Struts2
iText 2.1.7
flying-saucer-core-9.0.7
flying-saucer-pdf-9.0.7

Original issue reported on code.google.com by antoine....@mxns.com on 21 Apr 2015 at 2:36

GoogleCodeExporter commented 8 years ago
I just experienced the exact same issue on Windows. Changing the 
flying-saucer-core and flying-saucer-pdf versions to 9.0.6 fixed the issue.

Original comment by willdavidwarren on 28 Apr 2015 at 12:46