You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Peter Ross <pd...@gmail.com> on 2009/04/06 04:18:04 UTC

Using Prince XML to generate PDF of wicket page

Hi,

I'm new to wicket and I am looking at integrating Prince XML with Wicket.

Prince supplies a method

  public boolean convert(InputStream xmlInput, OutputStream pdfOutput)
throws IOException

What I would like to do is add this into the rendering pipeline for a
page, so that I can get the HTML of the page as a stream and then
return the page as a PDF.

I've explored the mailing list and examples and the closest example I
can find is for sending an email at

  http://www.wicket-library.com/wicket-examples/staticpages/

and I was wondering is this the correct approach, or should I be
looking at something else?

Thanks,
Pete

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


Re: Using Prince XML to generate PDF of wicket page

Posted by Peter Ross <pd...@gmail.com>.
On Mon, Apr 6, 2009 at 12:18 PM, Peter Ross <pd...@gmail.com> wrote:
> Hi,
>
> I'm new to wicket and I am looking at integrating Prince XML with Wicket.
>
> Prince supplies a method
>
>  public boolean convert(InputStream xmlInput, OutputStream pdfOutput)
> throws IOException
>
> What I would like to do is add this into the rendering pipeline for a
> page, so that I can get the HTML of the page as a stream and then
> return the page as a PDF.
>
> I've explored the mailing list and examples and the closest example I
> can find is for sending an email at
>
>  http://www.wicket-library.com/wicket-examples/staticpages/
>
> and I was wondering is this the correct approach, or should I be
> looking at something else?
>
I ended up pretty much following the code from the static pages
example, except I use requestCycle.setRedirect(false) rather than
using mount and having a special
BookmarkablePageRequestTargetUrlCodingStrategy.

As far as I can tell the only problem with doing it my way is the
"double submit" problem.  However as long as the page I render doesn't
do any state updates then this is not a problem because all that will
happen is that I will get the file being generated twice on the
server.

Here is the code that I'm using:

public class PdfPageRequestTarget extends BookmarkablePageRequestTarget {

    private String filename;

    public PdfPageRequestTarget(java.lang.Class PageClass, String filename) {
        super(PageClass);
        this.filename = filename;
    }

    @Override
    public void respond(RequestCycle requestCycle) {
            // In the staticpages example of wicket there is the
following comment:
            //   Unfortunately, you cannot use
            //   CapturingBookmarkablePageRequestTarget in an event listener
            //   like onClick() unless you change the application's
            //   IRequestCycleSettings to ONE_PASS_RENDER
            //
            // Thus we setRedirect to be false, meaning that ONE_PASS_RENDER is
            // enabled for just this request.  If you don't then s.ToString()
            // returns the empty string.
        requestCycle.setRedirect(false);

            // Save the web response we are rendering into
        WebResponse w = (WebResponse) requestCycle.get().getResponse();

            // Render into a string
        StringResponse s = new StringResponse();
        requestCycle.get().setResponse(s);
        super.respond(requestCycle);

            // Restore the web response
        RequestCycle.get().setResponse(w);

            // Now set up a text file which contains the requested pages html.
        ResourceStreamRequestTarget target = new
ResourceStreamRequestTarget(new StringResourceStream(s.toString(),
"text/plain"));
        target.setFileName(this.filename);

            // Now request that the result of rendering be the text file.
        requestCycle.get().setRequestTarget(target);
    }
}

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


Re: Using Prince XML to generate PDF of wicket page

Posted by arronlee <ar...@gmail.com>.
Something went wrong with my pdf reader. I wanna  convert pdf to text
<http://www.pqscan.com/pdf-to-text/>   first. Any suggestion will be
appreciated. Thanks in advance. 


-----
Best Regards,
Arron






Next Tomorrow is Another Day.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-Prince-XML-to-generate-PDF-of-wicket-page-tp1881598p4673690.html
Sent from the Users forum mailing list archive at Nabble.com.

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