-2

Could you please anyone tell me the way to create a pdf document for J2EE Application other than iText.

We are previously used the iText, but the problem is the html file (which is generated from Jsp) display is different with the generated PDF. So I need some other way to create a pdf as same as jsp display.

Any one please suggest me the libraries other than iText?

Thanks in Advance.

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
  • Why you do not search before asking? [link](https://stackoverflow.com/questions/7355025/create-pdf-with-java) – Milkmaid Nov 14 '17 at 08:54
  • Possible duplicate of [PDF Generation Library for Java](https://stackoverflow.com/questions/3986105/pdf-generation-library-for-java) – Milkmaid Nov 14 '17 at 11:42

2 Answers2

1

You are probably using iText 5 and XML Worker. Have you tried iText 7 and pdfHTML? See the HTML to PDF tutorial.

You will need:

You claim:

the problem is the html file (which is generated from Jsp) display is different with the generated PDF.

That is certainly true when you use HTMLWorker (which you shouldn't) and it's true in many cases for XML Worker. But we rewrote iText from scratch because of the mismatch between the old iText architecture and the requirements when converting HTML to PDF.

If you have a problem with the HTML to PDF conversion, please explain the problem in a question and tag that question as an iText question. If we can improve iText 7 + pdfHTML, why wouldn't we do that?

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
1

This is always tricky because HTML and PDF have differing purposes (with a lot of overlap). That means "simply" converting between the two is sometimes not going to work well.

You can

  1. Snapshot an image of the HTML and PDF the image. This has various downsides (can't search / extract text easily, larger, poor zoom, pagination) but is simple if it doesn't conflict with your requirements.
  2. Use a PDF system (like iText) to construct the PDF as desired using the same data. This is obviously more work (possibly a lot more), but is the optimal result in terms of PDF quality and fitness for purpose.
  3. Simplify/adjust your HTML so it converts better into PDF. This depends on what HTML tools/libraries you are using - you might not have much control over the HTML.
  4. Try various other conversion libraries to see if you find a tool that works better for your HTML.
Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
  • 1
    This is very good advice! +1 (I suggest to accept this answer. Note that the question already has 4 "close" votes; 1 extra vote and the question will be closed as "off-topic because the OP asks for a recommendation for a tool, product,...") – Bruno Lowagie Nov 15 '17 at 06:24