Hi,

Since Wicket 6.7.0 there is ComponentRenderer class which does exactly the
same.


On Sat, Jun 8, 2013 at 12:01 AM, Per Newgro <per.new...@gmx.ch> wrote:

> Found the solution already. I did it that way:
>
> public class FlyingSaucerPdfResource extends ByteArrayResource {
>
>     public FlyingSaucerPdfResource() {
>         super("application/pdf");
>     }
>
>     @Override
>     protected byte[] getData(Attributes attributes) {
>         ByteArrayOutputStream os;
>         try {
>             CharSequence buf = renderPage(HomePage.class,
> attributes.getParameters());
>             ITextRenderer renderer = new ITextRenderer();
>             renderer.**setDocumentFromString(buf.**toString());
>             renderer.layout();
>             renderer.createPDF(os = new ByteArrayOutputStream());
>             os.close();
>         } catch (IOException | DocumentException e) {
>             throw new RuntimeException(e);
>         }
>         return os.toByteArray();
>     }
>
>     private CharSequence renderPage(final Class<? extends Page> pageClass,
>             PageParameters parameters) {
>
>         final RenderPageRequestHandler handler = new
> RenderPageRequestHandler(
>                 new PageProvider(pageClass, parameters),
>                 RedirectPolicy.NEVER_REDIRECT)**;
>
>         final PageRenderer pageRenderer = getApplication()
>                 .getPageRendererProvider().**get(handler);
>
>         RequestCycle originalRequestCycle = RequestCycle.get();
>
>         BufferedWebResponse tempResponse = new BufferedWebResponse(null);
>
>         RequestCycleContext requestCycleContext = new RequestCycleContext(
>                 originalRequestCycle.**getRequest(), tempResponse,
>                 getApplication().**getRootRequestMapper(),
> getApplication()
>                         .getExceptionMapperProvider().**get());
>         RequestCycle tempRequestCycle = new RequestCycle(**
> requestCycleContext);
>
>         final Response oldResponse = originalRequestCycle.**getResponse();
>
>         try {
>             originalRequestCycle.**setResponse(tempResponse);
>             pageRenderer.respond(**tempRequestCycle);
>         } finally {
>             originalRequestCycle.**setResponse(oldResponse);
>         }
>
>         return tempResponse.getText();
>     }
>
>     private Application getApplication() {
>         return Application.get();
>
>     }
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: 
> users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org>
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to