You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ashwanth Kumar <as...@gmail.com> on 2010/01/01 07:30:51 UTC

Help with Tapestry Page and iText

Hello,

Happy new year to all!! (Its new year here in India)..

Okay, i need a small help! I want to generate a PDF file, based on the
generated page in Tapestry.. I've plans of using iText to generate PDF. Can
any one help me? How to get it done!!

PS: On cliking Download PDF link, the PDF should be generated on the fly,
and then sent to user.

 - Ashwanth Kumar

Re: Help with Tapestry Page and iText

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 01 Jan 2010 09:11:13 -0200, Inge Solvoll <in...@gmail.com>  
escreveu:

> Shouldn't be too hard.
>
> Do this in your page class:
>
> Object afterRender(MarkupWriter writer) {
> Document doc = writer.getDocument();
> ITextDocument itextDoc = convertT5DocToItext(doc);
> return new ITextStreamResponse(itextDoc);
> }

What would do the HTML to PDF conversion in this case?
There's one project, Flying Saucer (https://xhtmlrenderer.dev.java.net/),  
that renders HTML to various formats, including to the screen (as a Swing  
component) and PDF. It uses iText internally. This article shows how you  
do it:  
http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html.

> One example technique for making a PDF version of your pages is to  
> subclass your page and only include the afterRender method above. I'm  
> sure there are other (more elegant) ways to do this than the example I  
> made here!

I guess this could be implemented as a mixin.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Help with Tapestry Page and iText

Posted by Inge Solvoll <in...@gmail.com>.
Shouldn't be too hard.

Do this in your page class:

Object afterRender(MarkupWriter writer) {
Document doc = writer.getDocument();
ITextDocument itextDoc = convertT5DocToItext(doc);
return new ITextStreamResponse(itextDoc);
}

I think you can also gain access to all generated markup from the
MarkupWriter (writer.toString()), and just pass the generated HTML on to
your PDF writer.

One example technique for making a PDF version of your pages is to subclass
your page and only include the afterRender method above. I'm sure there are
other (more elegant) ways to do this than the example I made here!

On Fri, Jan 1, 2010 at 7:30 AM, Ashwanth Kumar <as...@gmail.com>wrote:

> Hello,
>
> Happy new year to all!! (Its new year here in India)..
>
> Okay, i need a small help! I want to generate a PDF file, based on the
> generated page in Tapestry.. I've plans of using iText to generate PDF. Can
> any one help me? How to get it done!!
>
> PS: On cliking Download PDF link, the PDF should be generated on the fly,
> and then sent to user.
>
>  - Ashwanth Kumar
>