/** * Saves the rendered report to the specified DeliverFile component, which the caller will return * back to the user. * * @param file the DeliverFile component to save the file into * @return a Throwable if an error occurred (which the caller should display to the user), or null * if the operation was successful */ public Throwable deliverTo(DeliverFile file) { try { NSMutableDataOutputStream outputStream = new NSMutableDataOutputStream(); PDFRenderOption option = new PDFRenderOption(); option.setOutputFormat("PDF"); option.setOutputStream(outputStream); IRenderTask task = reportEngine().createRenderTask(reportDocument()); task.setRenderOption(option); org.mozilla.javascript.Context.enter(); task.render(); org.mozilla.javascript.Context.exit(); outputStream.close(); close(); file.setFileData(outputStream.data()); file.setContentType("application/pdf"); file.setStartDownload(true); file.setDeliveredName(generatedReport().description() + ".pdf"); } catch (Exception e) { return e; } return null; }