Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any way improve the performance of FlyingSaucer?
    text
    copied!<p>I've followed <a href="http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html" rel="nofollow">this article</a> to use FlyingSaucer to convert XHTML to PDF and it's brilliant but has one major downfall... it's ridiculously slow!</p> <p>I'm finding that it takes between 1 and 2 minutes to render a PDF from an XHTML, regardless of how simple that page is.</p> <p>Basic code:</p> <pre><code>import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.xhtmlrenderer.pdf.ITextRenderer; import com.lowagie.text.DocumentException; public class FirstDoc { public static void main(String[] args) throws IOException, DocumentException { String inputFile = "firstdoc.xhtml"; String url = new File(inputFile).toURI().toURL().toString(); String outputFile = "firstdoc.pdf"; OutputStream os = new FileOutputStream(outputFile); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(url); renderer.layout(); renderer.createPDF(os); os.close(); } } </code></pre> <p>Sample XHTML:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;My First Document&lt;/title&gt; &lt;style type="text/css"&gt; b { color: green; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt; &lt;b&gt;Greetings Earthlings!&lt;/b&gt; We've come for your Java. &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Does anyone know how to improve the performance of FlyingSaucer?</p> <p>Failing that, is anyone able to recommend an alternative Java library which is effective at rendering a PDF from a URL to an (X)HTML document with external CSS and images generated from URLs?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload