public Object generatePDF(Document dataset) throws IOException
{
// Open shell XDP containing XFA template based on servlet context (in this case webapp root)
String source = FlexContext.getServletContext().getRealPath("/pdfgen_contact/contact.xdp");
XDPXFAHelper helper = new XDPXFAHelper();
helper.open(source);
// Import XFA dataset
helper.importDataset(dataset);
// Save new PDF as a byte array in the current session
byte[] bytes = helper.saveToByteArray();
String uuid = UUIDUtils.createUUID();
FlexSession session = FlexContext.getFlexSession();
session.setAttribute(uuid, bytes);
// Close any resources
helper.close();
HttpServletRequest req = FlexContext.getHttpRequest();
String contextRoot = "/lcds-samples";
if (req != null)
contextRoot = req.getContextPath();