Created
May 14, 2010 10:08
-
-
Save indaco/401005 to your computer and use it in GitHub Desktop.
Generate PDF from XDP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
ByteArrayInputStream pdfInputStream = null; | |
try { | |
IWDPDFDocumentHandler pdfDocumentHandler = WDPDFDocumentFactory.getDocumentHandler(); | |
IWDPDFDocumentCreationContext pdfDocCreationContext = pdfDocumentHandler.getDocumentCreationContext(); | |
String templateUrl = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),this.xdpSource); | |
InputStream template = new FileInputStream(templateUrl); | |
ByteArrayOutputStream templateStream = inputToOutputStream(template); | |
byte[] pdfStream = wdContext.currentContextElement().getPdfSource(); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
try { | |
baos.write(pdfStream); | |
} catch (IOException e) { | |
this.msgMgr.reportException(e.getMessage()); | |
} | |
pdfDocCreationContext.setData(baos); | |
pdfDocCreationContext.setTemplate(templateStream); | |
pdfDocCreationContext.setDynamic(true); | |
IWDPDFDocument pdf = pdfDocCreationContext.execute(); | |
pdfInputStream = (ByteArrayInputStream) pdf.getData();//PDFAsStream(); | |
try { | |
this.msgMgr.reportSuccess(convertStreamToString(pdfInputStream)); | |
} catch (IOException e) { | |
this.msgMgr.reportException(e.getMessage()); | |
} | |
IWDResource pdfResource = | |
WDResourceFactory.createCachedResource(pdf.getPDF(), "test.pdf", WDWebResourceType.PDF); | |
//pdfResource element is bounded to FileDownload UI element resource property | |
wdContext.currentContextElement().setPdfResource(pdfResource); | |
} catch (Exception e) { | |
this.msgMgr.reportException(e.getMessage()); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment