Re: Webobjects-dev Digest, Vol 6, Issue 402
Re: Webobjects-dev Digest, Vol 6, Issue 402
- Subject: Re: Webobjects-dev Digest, Vol 6, Issue 402
- From: Robert Tupelo-Schneck <email@hidden>
- Date: Thu, 30 Apr 2009 09:02:41 -0400
shravan kumar <email@hidden> wrote:
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.
In terms of generating the PDF, I've had good luck with the
combination of Flying Saucer (core-renderer.jar) and iText (itext-
paulo-155.jar). With those libraries, the following code should
generate the byte array of a PDF for the component:
WOContext context = (WOContext) context().clone();
MyComponent component = (MyComponent)
application().pageWithName(MyComponent.class.getName(), context);
String html = component.generateResponse().contentString();
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new
ByteArrayInputStream(html.getBytes("UTF-8")));
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
renderer.layout();
renderer.createPDF(os);
os.close();
byte[] pdfBytes = os.toByteArray();
Then you should be able to massage those bytes into an email attachment.
Note: 'It is important to add "-Djava.awt.headless=true" to the
"Additional Arguments" list' of your WebObjects app.
Robert
_______________________________________________
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