Child pages
  • Development-PDF Generation
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


You might want to also review the Returning a File example.

Zak Burke's Example

It is important to add "-Djava.awt.headless=true" to the "Additional Arguments" list to suppress a console window running WOBootstrap that will try to pop up and then fail to close, which seems to prevent the thread from returning, which causes the app to hang.

private ByteArrayOutputStream pdf()
// binary container for PDF
ByteArrayOutputStream out = null;


Unknown macro: { // assume these exist String xsl, xml; TransformerFactory transformerFactory = TransformerFactory.newInstance(); // configure FOP, apache's XML->PDF transformer Fop fop = new Fop(MimeConstants.MIME_PDF); out = new ByteArrayOutputStream(); fop.setOutputStream(out); // configure XSLT transformer Source xsltSrc = new StreamSource(new StringReader(xsl)); Transformer transformer = transformerFactory.newTransformer(xsltSrc); // pipe XSL transformation through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // grab XML input stream Source src = new StreamSource(new StringReader(xml)); // Start the transformation and rendering process transformer.transform(src, res); }

catch (Exception e)

Unknown macro: { // actually, catch the following, one by one}

return out;

public void appendToResponse(WOResponse response, WOContext context)

Unknown macro: { ByteArrayOutputStream out = pdf(); // without data, show the PDF page, which is just an error message. if (out == null) super.appendToResponse(response, context); // assume this exists String filename; response.setHeader("application/pdf", "Content-Type"); response.setHeader("" + out.size() + "", "Content-Length"); response.setHeader("attachment;filename=" + filename, "Content-Disposition"); response.setContent(new NSData(out.toByteArray())); }


  • No labels