| From | Sent On | Attachments |
|---|---|---|
| Juan José Casanova Guaita | Aug 31, 2009 10:29 am | |
| David Bolton | Aug 31, 2009 12:56 pm | |
| Juan José Casanova Guaita | Sep 1, 2009 5:40 am | |
| Andrew Hunt | Sep 1, 2009 2:52 pm |
| Subject: | Re: Getting blank PDF's | |
|---|---|---|
| From: | Andrew Hunt (ahun...@yahoo.com.au) | |
| Date: | Sep 1, 2009 2:52:13 pm | |
| List: | net.java.dev.xhtmlrenderer.users | |
Hi
Might be barking up the wrong tree, but recall having this happen to me when I
was developing our solution, and vaguely recall the issue was with the [lack of
a or wrong] namespace handler.
Believe I originally had renderer.setDocument(htmlDoc) or renderer.setDocument(htmlDoc, url) but the code is now
...
renderer.setDocument(htmlDoc, url, new XhtmlNamespaceHandler());
...
Our total method is (I usually use jDom, hense the Document to Document twist in
the middle):
public static void createPDFFileFromDoc(String inputFileName, String
outputFileName) throws DocumentException, IOException, JDOMException {
SAXBuilder sb = new SAXBuilder();
/* This is needed to avoid a Connection timeout on the DTD */
EntityResolver er = sb.getEntityResolver();
if (er == null) {
sb.setEntityResolver(FSEntityResolver.instance());
}
DOMOutputter outputter = new DOMOutputter();
org.jdom.Document html = sb.build(new File(inputFileName));
org.w3c.dom.Document htmlDoc = outputter.output(html);
OutputStream os = new FileOutputStream(outputFileName); String url = new File(inputFileName).toURI().toURL().toString();
ITextRenderer renderer = new ITextRenderer();
/*
* Following produces output that is not quite correctly formatted.
Specifically, columns are not correct.
* renderer.setDocument(htmlDoc, url, new
XhtmlCssOnlyNamespaceHandler());
*
* However, the following works!
*/
renderer.setDocument(htmlDoc, url, new XhtmlNamespaceHandler());
renderer.layout();
renderer.createPDF(os);
os.close();
}
And does exactly what we need. I tried a couple of the other NamespaceHandler
interface implementations provided, but this is the only one that implemented
the column /table formatting etc correctly for us.
Regards...Andrew
Juan José Casanova Guaita <juan...@gmail.com> 01/09/2009 10:41 PM Please respond to use...@xhtmlrenderer.dev.java.net To use...@xhtmlrenderer.dev.java.net cc
Subject Getting blank PDF's
Hi David, the closing tag issue that you point in your email was just a mistake when I copied the HTML into my first email. If I'd tried to generate the PDF with this html I'd received the following error:
org.xml.sax.SAXParseException: The element type "body" must be terminated by the matching end-tag "</body>".
And the PDF file would be not generated at all.
My problem is different, FS generates a blank PDF file without report any error, and having the right xhtml for input.
Any other idea? :(
--------------------------------------------------------------------- To unsubscribe, e-mail: user...@xhtmlrenderer.dev.java.net For additional commands, e-mail: user...@xhtmlrenderer.dev.java.net
__________________________________________________________________________________ Find local businesses and services in your area with Yahoo!7 Local. Get started: http://local.yahoo.com.au





