Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java create PDF or Image from an invalid HTML

I want to create PDF (or any of image formats [png, jpg, bmp..]) from an 'invalid' HTML file using Java. I googled it and find a tool: iText, and some of tutorials that using iText to create PDF from HTML with Java.

In this tutorial (X)HTML to PDF with Java , it works for a valid HTML correctly and i had a PDF file like this. But if i tried to create PDF from my HTML i had some errors.

First of all my HTML is not well formed and unfortunately does not possible to change. I uploaded it to here and W3C's validator found 28 errors.

My options are:

  • First clean and valid my HTML and create PDF soon.
  • Find another tool (which works for my problem).
  • Your suggestion (using Java).
  • Last option; use an another platform (.net, Php, Python etc.) and using Webservices from my application.

Please help me about this issue. Thank you in advance

like image 636
Oguz Ozkeroglu Avatar asked Feb 21 '23 06:02

Oguz Ozkeroglu


1 Answers

You could use a tool like http://jtidy.sourceforge.net/ to fix the HTML for you and run iText against the jTidy's output...

like image 162
Alexander Pavlov Avatar answered Mar 04 '23 04:03

Alexander Pavlov