The Source for Java Technology Collaboration

Home » java.net Forums » Java Web Services and XML » Java WS & XML Community News

Thread: How to convert HTML to PDF?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Mar 20, 2009 4:33 PM by: mloayzagahona Threads: [ Previous | Next ]
tokajac

Posts: 7
How to convert HTML to PDF?
Posted: Mar 19, 2009 3:45 PM
 
  Click to reply to this thread Reply

Hello!


I'm developing Tomcat/Struts application.
I want to convert, for example, http://www.google.com to PDF.
I found iText solutions, but i still haven't made them to work. Any experience with this? Any other suggestion?

All useful hints are welcome!


Regards

greeneyed

Posts: 35
Re: How to convert HTML to PDF?
Posted: Mar 20, 2009 6:35 AM   in response to: tokajac
 
  Click to reply to this thread Reply

I'm not aware of a direct path to do it but...
.- XHTMLRenderer (a.k.a. the Flying Saucer) is a library that allows you to convert XHTML to PDF quite easily (https://xhtmlrenderer.dev.java.net/)
.- HTMLCleaner is a library that can "clean" a given HTML page and turn it into an XHTML page (http://htmlcleaner.sourceforge.net/)

I've used them separately and they worked fine for me, so you just have to connect both and voilà :).

S!

tokajac

Posts: 7
Re: How to convert HTML to PDF?
Posted: Mar 20, 2009 9:58 AM   in response to: greeneyed
 
  Click to reply to this thread Reply

Thank you for your answer greeneyed!


I tried http://htmlcleaner.sourceforge.net/javause.php
but have no success so far.

How to use http://htmlcleaner.sourceforge.net/ in Java? Is there any working example?


Regards

P.S.
I also posted this topic on:
https://sourceforge.net/forum/forum.php?thread_id=3123464&forum_id=637246

greeneyed

Posts: 35
Re: How to convert HTML to PDF?
Posted: Mar 20, 2009 12:14 PM   in response to: tokajac
 
  Click to reply to this thread Reply

Well, the basic example is the page that you show, that's the most basic "stuff".

For a more complex example, you can have a look at the filter I implemented for our framework:

http://fisheye5.cenqua.com/browse/webleaf/source/org/leaf/filters/HTMLCleanerFilter.java?r=1.2

Basically the code you are looking for is the code inside the doFilterMethod:
http://fisheye5.cenqua.com/browse/webleaf/source/org/leaf/filters/HTMLCleanerFilter.java?r=1.2#l164

and also the init method where the objects are initialised:
http://fisheye5.cenqua.com/browse/webleaf/source/org/leaf/filters/HTMLCleanerFilter.java?r=1.2#l232

The rest of the code is parameter reading so the filter can be configured with all the options that HTMLCleaner can use.

We use this filter in combination with other filters to get content in HTML external to the application and convert it to XHTML so it can be used as XML for several purposes.

S!

mloayzagahona

Posts: 1
Re: How to convert HTML to PDF?
Posted: Mar 20, 2009 4:33 PM   in response to: tokajac
 
  Click to reply to this thread Reply

Hi.

You could review this post

http://mloayzagahona.blogspot.com/2007/07/convert-html-to-pdf-online.html

Greetings.

Have a great day




 XML java.net RSS