Re: Generate PDF from dynamically generated WOComponents...
Re: Generate PDF from dynamically generated WOComponents...
- Subject: Re: Generate PDF from dynamically generated WOComponents...
- From: Jean-Francois Veillette <email@hidden>
- Date: Wed, 29 Apr 2009 19:01:13 -0400
a 4th option would be UJAC: http://ujac.sf.net
It is similar to xml-fo, but lot simpler and closer to html. It is
also more flexible. It would be my first choice if only the only
caveat is that it is not 'standard', so it will depend on your
organisation and on long term plan for what you are doing.
- jfv
Le 09-04-29 à 18:31, Hugi Thordarson a écrit :
A good and swineflufree afternoon to ya'll.
If you already have HTML that you want to render as PDF, The Flying
Saucer Project is your new saviour.
1. Go to https://xhtmlrenderer.dev.java.net/ and download a stable
binary.
2. Add the three required jars to your project (iText/xml/core-
renderer).
3. Use something like the following method (or one of other dozen
methods) to render your HTML to PDF:
/**
* Uses xhtmlrenderer to generate a PDF-file from XHTML.
*
* @param htmlString HTML String to convert to PDF. Valid XHTML
only, please.
* @return Beautifully rendered PDF data.
*/
public static byte[] convertHTMLToPdf( String htmlString ) {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString( htmlString );
renderer.layout();
renderer.createPDF( os );
os.close();
return os.toByteArray();
}
catch( Exception e ) {
logger.error( "Could not convert HTML to PDF", e );
}
return null;
}
If you want alternatives, I've been through a few hoops with PDF-
generation in my days, and this is my opinion on some of them:
- FO processed with FOP: Flexible, but FO XML syntax is an entirely
new language to learn, very verbose and an overkill for 99% of use
cases. FOP implementation of FO lacked features I wanted, and I've
deprecated use of FO within our corporation.
- PD4ML: My previous tool of choice for the simple things. Converts
HTML to PDF, but is neither free nor OSS. And Flying Saucer Project
does nicer rendering anyway.
- iText, using the java APIs: Very powerful, very flexible, a
control freak's dream :-). I use it for mission critical stuff where
I need maximum control over presentation and want to generate tiny,
beautiful (binarily talking) files. It's a bit like creating
documents using the DOM API, only simpler and nicer (thank god).
Cheers,
- Hugi
ps: If you don't know how to get HTML from your rendered component -
then to get you started, you can call
myPDFToBeComponent.context().response().contentString().
On 29.4.2009, at 18:26, shravan kumar wrote:
Hello Group,
We have an app, where a module is presented to the user in a wizard
fashion i.e., this module has several pages and user can navigate
from one page to another using the wizard navigation controls and
jump to any sections as required.
Once the user has completed one trip to this wizard i.e., if for
once user has watched all the screens in the wizard then upon user
Finalizing the wizard data we would need to create a pdf with the
content in each screen/ page of the wizard automatically and email
this pdf to our support team.
We have components in this wizard designed and are functional. Now
we need to get the pdf document out of this wizard generated
automatically upon user finalizing the wizard data from back end.
User is not suppose to invoke this pdf generation but rather should
happen automatically.
Any one please advise me the best way to achieve this and also
suggest if we have any tools already available over the internet
and I can reuse them here.
Please let me know if I did not present myself correctly.
Thanks in advance,
Shravan Kumar. M
------------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden