Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Convert HTML to PDF (100% Java)

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
...and Byron is of course referring to Apache Cocoon
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic