Export to GitHub

flying-saucer - issue #261

CSS not being applied to generated PDF


Posted on Apr 21, 2015 by Happy Lion

<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"&gt; <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

Comment #1

Posted on Apr 28, 2015 by Massive Panda

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.

Status: New

Labels:
Type-Defect Priority-Medium