danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.92k stars 358 forks source link

Feature differences between openhtmltopdf and flyingsaucer #80

Closed seizmo closed 5 years ago

seizmo commented 7 years ago

It would be greatly appreciated if you could add a section to the README that details the differences between openhtmltopdf and flyingsaucer in terms of features (apart from using libraries with better licenses).

Are you behind, on par or even exceeding the features and HTML/CSS-compatibility of flyingsaucer?

rototor commented 7 years ago

HTML/CSS compatibilty should be very similar. It seems flyingsaucer gets a little bit of development now again, the project was very quiet for a long time.

As you may already know: Don't expect to throw any HTML on this library and get perfect printouts from it. To get good results you must tune your HTML to this library and use some CSS extensions. Many HTML5 features like "display:flex" wont get into this library nor flyingsaucer, because they are very complex to implement and you can already "fake" them using tables. Yes, tables are bad in normal HTML. But here you want to get a fixed width PDF printout, so you need to use whats there. On the other side their are extensions like -fs-table-paginate: paginate; which allows you to get multipage tables with repeated headers. This is something which normal browser can't do. They usually put pagebreaks at random points which makes them ugly.

The features I added to openhtmltopdf are features which I needed:

See the README for other changes. Currently the differences between flyingsaucer and openhtmltopdf are not that big. Beside using the old unmaintained iText2 vs active developed OpenPDFBox.

rajaningle commented 6 years ago

In my opinion I can see one major difference between the two is Flying saucer with itext gives the ability to add pages to the pdf incrementally. That means it will allow you to create pdf and add one or more pages as you stream data and that seems memory efficient as well as fast. openhtmltopdf is lacking on that front and don't support page addition which makes it render the entire thing at once which is causing performance issues. openhtmltopdf team is doing a great job in resolving this open issue. 180 but apart from this i think both libraries are similar and really good at generating pdf from HTML/CSS I couldn't find other library which supports the same and as feature rich as these two. @rototor Flying saucer now supports itext5.

rototor commented 6 years ago

@rajaningle iText 5 is a no go at least for me and my customers, as AGPL is more or less incompatible with anything used commercially. If your public internet facing web server is generating bills using iText 5, you would need to give all your sources to everyone getting a bill PDF. So you are required to buy a licence, and prices are not public visible (you must request a quote...)

You should be able to add pages to an existing document using this lib too. You just must specify a PDDocument of a existing PDF. Also the memory needed to generate a document should not be that much different, as you need to have the whole W3C DOM in memory for flying saucer too. The only big difference is that PDFBox holds the whole document in memory by default, but you can configure that.

The lossless image compression is currently better in iText, but I am working on that. Especially in terms of image encoding iText has many special cases to handle image data very efficient and avoid reencoding PNGs and JPEGs. At least iText 2 had that — never looked into iText 5. I am not sure if that is worth the hassle, at least I won’t implement that in PDFBox.

rajaningle commented 6 years ago

@rototor Thanks for insight on the licensing part and details about the other sections but I was really struggling to do incremental page add with openhtmltopdf i know it is available with pdfbox but could not find a way to do it with openhtmltopdf also it is not mentioned in docs.

If you can provide one example to add pages from html that would be really great.

Thanks.

rototor commented 6 years ago

@rajaningle For an example look into #222 ConcateOutputTest.testConcateOutput()

taras19921 commented 6 years ago

Hi all! My svg image is not displayed on PDF file. I have svg image on my html template. This is a snippet of my code:

PdfRendererBuilder builder = new PdfRendererBuilder(); builder.defaultTextDirection(BaseRendererBuilder.TextDirection.LTR); builder.useSVGDrawer(new BatikSVGDrawer()); builder.useMathMLDrawer(new MathMLDrawer()); builder.addDOMMutator(LaTeXDOMMutator.INSTANCE); builder.useDefaultPageSize(210, 297, BaseRendererBuilder.PageSizeUnits.MM); builder.withHtmlContent(html, ""); builder.toStream(os); builder.run();

What I'm doing wrong or what I'm missing?

rototor commented 6 years ago

@taras19921 You should open a new issue for this, as it is not related to this issue.

Your builder looks fine, there may be something wrong the HTML you supply. Please open a new issue and provide the HTML. Thanks.

taras19921 commented 6 years ago

I've opened a new issue: https://github.com/danfickle/openhtmltopdf/issues/258

danfickle commented 5 years ago

Finally added a list of differences with Flying Saucer in the README. Will add to it over time. Thanks everyone.