Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Convert HTML to PDF (100% Java)

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all,
Does anyone know how to convert HTML to PDF using a completely Java, platform-independent solution?
Thanks!
sev
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use HtmlParser to parse the HTML and produce a corresponding XSL-FO document (manual coding, I'm afraid) and then run the XSL-FO through Apache FOP to get a PDF.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at:
http://www.lowagie.com/iText/docs.html
 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sever oon:
Hey all,
Does anyone know how to convert HTML to PDF using a completely Java, platform-independent solution?
Thanks!
sev


The easiest way to do this is to download HTMLdoc from www.easysw.com
What it provides is a dos command which if excuted from the java runtime produces a PDF for the specified HTML.
What you have to do is to pass the html file name ( source) and the PDF file name( target ) ... Its all given in the manual .
I did it today
all the best
 
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're using that too, but I don't believe it is 100% java. I believe instead that it is actually C/C++. We're calling it using Java from within an Oracle PL/SQL Procedure.
 
sever oon
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all...
Unfortunately I can't use any DOS stuff--that's not exactly 100% Java (plus, we have to be able to run this software on customers' servers--they're not going to all be running a DOS-based system).
Converting to XSL-FO solves the problem but I'm trying to avoid doing that work--if I was redesigning the system I'd have everything in FO and transform it from there to the format required for whatever medium (HTML, PDF, etc). That's not an option in this case because it's so hard to get to FO from HTML right now...
Looks like iText gets the prize. Now I only have to see if it costs money...
Thanks again all.
sev
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Test it carefully too; we tried iText, but it didn't render our HTML accurately. We would have needed to make some changes to it in order to get it to reproduce in a WYSIWYG fashion.
I know you don't want to re-architect the application, that's why we took the approach we did, but depending upon how much you see the application changing and the potential for it to be exposed via other devices (i.e. pda, etc.) you might want to look at creaing generic xml representations of screens and using Jakara Cacoon to render it in whatever way you need it. It does, by the way have a nice PDF renderer.
Good luck!
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and Byron is of course referring to Apache Cocoon
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic