empty PDF

638 views
Skip to first unread message

Eric Gavaldo

unread,
Aug 31, 2013, 4:21:37 PM8/31/13
to flying-sa...@googlegroups.com
Hi there,
For an unknown reason the PDF I generate from an XHML is just empty.
The XHTML is apparently well parsed, the css is found with no problem but the output is just a empty single page.

The code I'm using:

        FileOutputStream os = null;
        try {
            // input
            File inputFile = new File(fileDescriptor + ".html");
            String inputXhtml = CFileUtils.FileToString(inputFile);
            System.err.println("- - - - inputXhtml = " + inputXhtml);
           
            // output
             os = new FileOutputStream(fileDescriptor + ".pdf");
           
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocument(inputFile);
            renderer.layout();
            renderer.createPDF(os, true);
            renderer.finishPDF();
            os.close();
            os = null;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) { // Flying Saucer exception
            e.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    // ignore
                }
            }
         }

I also tried to open the XHTML in a browser to verify it was correct: no problme either the HTML is correctly rendered.
Any idea?
Thanks,

Peter Brant

unread,
Sep 1, 2013, 3:19:27 PM9/1/13
to flying-sa...@googlegroups.com
Could there be a RuntimeException or Error that's being logged somewhere else?  or alternatively could stderr be writing to an unexpected place?

I'm pretty sure folks have successfully used FS in combination with CF before so all things being equal it should work.

Pete




--
You received this message because you are subscribed to the Google Groups "Flying Saucer Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flying-saucer-u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Eric Gavaldo

unread,
Sep 2, 2013, 6:41:12 AM9/2/13
to flying-sa...@googlegroups.com
I'm sure no exception are thrown or error output somewhere else as if I introduced an error on purpose (invalid XHTML) I can see the errors.
I really guess there's something special in the original XHTML that flying saucer doesn' like...

The traces I get are:
org.docx4j.org.xhtmlrenderer.load INFO:: SAX XMLReader in use (parser): com.sun.org.apache.xerces.internal.parsers.SAXParser
org.docx4j.org.xhtmlrenderer.load INFO:: SAX XMLReader in use (parser): com.sun.org.apache.xerces.internal.parsers.SAXParser
org.docx4j.org.xhtmlrenderer.load INFO:: SAX XMLReader in use (parser): com.sun.org.apache.xerces.internal.parsers.SAXParser
org.docx4j.org.xhtmlrenderer.load INFO:: SAX XMLReader in use (parser): com.sun.org.apache.xerces.internal.parsers.SAXParser
org.docx4j.org.xhtmlrenderer.load INFO:: SAX XMLReader in use (parser): com.sun.org.apache.xerces.internal.parsers.SAXParser
org.docx4j.org.xhtmlrenderer.load INFO:: SAX XMLReader in use (parser): com.sun.org.apache.xerces.internal.parsers.SAXParser
org.docx4j.org.xhtmlrenderer.load INFO:: Loaded document in ~73ms
org.docx4j.org.xhtmlrenderer.load INFO:: resources/css/XQual.css is not a URL; may be relative. Testing using parent URL file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/
org.docx4j.org.xhtmlrenderer.load INFO:: TIME: parse stylesheets  126ms
org.docx4j.org.xhtmlrenderer.match INFO:: media = print
org.docx4j.org.xhtmlrenderer.load INFO:: Requesting stylesheet: file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/resources/css/XQual.css
org.docx4j.org.xhtmlrenderer.css-parse WARNING:: (file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/resources/css/XQual.css) spacing is an unrecognized CSS property at line 10. Ignoring declaration.
org.docx4j.org.xhtmlrenderer.css-parse WARNING:: (file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/resources/css/XQual.css) Found = where : was expected at line 33. Skipping declaration.
org.docx4j.org.xhtmlrenderer.match INFO:: Matcher created with 196 selectors
org.docx4j.org.xhtmlrenderer.load INFO:: resources/images/xqual_thumbnail.gif is not a URL; may be relative. Testing using parent URL file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/
org.docx4j.org.xhtmlrenderer.load INFO:: resources/66_ScreenHunter_100 May. 27 00.51.gif is not a URL; may be relative. Testing using parent URL file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/
org.docx4j.org.xhtmlrenderer.load INFO:: resources/images/IconAttachment.gif is not a URL; may be relative. Testing using parent URL file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/
org.docx4j.org.xhtmlrenderer.load INFO:: resources/images/IconAttachment.gif is not a URL; may be relative. Testing using parent URL file:/C:/Users/egavaldo/Documents/REPORTS/failed_pdf/

I attached the HTML and the generated pdf (1k but only a blank page)

Pretty short of ideas now...

failed_pdf.zip
failed_pdf.pdf

Peter Brant

unread,
Sep 4, 2013, 9:22:44 AM9/4/13
to flying-sa...@googlegroups.com
In your original code, it looks like you're closing the document twice.  Try

            renderer.createPDF(os);

instead of

            renderer.createPDF(os, true);
            renderer.finishPDF();

I've attached the output of running your HTML file through the ToPDF utility class at the command line.

Pete






failed_pdf.pdf

Eric Gavaldo

unread,
Sep 4, 2013, 12:12:46 PM9/4/13
to flying-sa...@googlegroups.com

Hi Pete,

Yes, I made thousands of tests without success so it may be the reason but I'm almost sure it won't as I tried to use the finishPdf() method only lately (in case the true argument wouldn't work). I'll try anyway and will let you know...

Your output is exactly what I'm looking for though :) So it means at least that the problems does not come from the HTML itself. How would it be possible that the command line works but not the API?

Many thanks for your feedback Pete!!! I'll let you know the results...

Eg\\*

Reply all
Reply to author
Forward
0 new messages