Search code examples
javaitextpdfboxflying-saucerpdfrenderer

convert from html to pdf and to image java


Well, I DID READ ALMOST ALL THE QUESTIONS HERE ABOUT THIS TOPIC!

I need an API - not at tool to convert in a very high quality from PDF to image.

So I didn't find any direct tool, and I used: HTML to PDF and PDF to image.

I tried:

  • PDFRenderer
  • FDFBOX
  • PDFONE
  • HTML2IMAGE
  • FLYING-SAUCE
  • ITEXT
  • JPEDAL
  • PDFCrown

Only the commerical ones (PDFCrown and PDFBox) came out with good results.

I thought that Java is for open source projects!

Am I missing any library that prints out in a high quality images from HTML (could be also from PDF, I can pay for half the way..)


Solution

  • I used the wonderful tool:

    WKHTMLTOPDF.

    It's very easy - just a command line.

    Installation:

    1. Download from here the version. To windows I used: wkhtmltox-0.11.0_rc1-installer.exe file.
    2. Run the installer
    3. Save your HTML to a file on your disk.
    4. In java, Runtime.getRuntime().exec(wkhtmltopdf file.jpg myhomepage.jpg)

    That's it! so easy to use:)