cancel
Showing results for 
Search instead for 
Did you mean: 

setTemplate - how to access xdp file by code

former_member182374
Active Contributor
0 Kudos

Hello Experts,

I'm using ADS in my WDJ project.

When I create new adobe form the xdp is created under src -> configuration -> Components -> <Component Name> -> xdp files.

In order to create PDF on the fly I need to use the 'setTemplate' method of the interface 'IWDPDFDocumentCreationContext'.

Although the method has several signatures:

void setTemplate(byte[] template)

void setTemplate(OutputStream templateStream)

void setTemplate(String URL)

I still need to access the xdp source file.

I couldn't find API to access xdp file under 'src -> configuration -> Components -> <Component Name>'.

A possible workaround is to copy the xdp to the component's mimes folders and access it by

templateUrl = WDURLGenerator.getAbsoluteWebResourceURL(wdComponentAPI.getDeployableObjectPart(), "CopyOf.xdp");

I want to avoid this solution.

So, how can I access the xdp files without copy it?

Version is 7.00 SP22.

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

Stefan-EA
Contributor
0 Kudos

Omri,

I've had this issue in the past and the only workaround I found was what you posted. If you do find a solution, please update this thread. Thanks.

former_member182374
Active Contributor
0 Kudos

Solved it on my own (or to be more precise by using to following code):

https://gist.github.com/403956

try{

IWDPDFDocumentHandler pdfDocumentHandler = WDPDFDocumentFactory.getDocumentHandler();

IWDPDFDocumentCreationContext pdfNewDocContext = pdfDocumentHandler.getDocumentCreationContext();

String templateUrl = WDURLGenerator.getPublicResourcePath(wdComponentAPI.getDeployableObjectPart(), "IF.xdp");

InputStream template = new FileInputStream(templateUrl);

byte[] byteFileArray = new byte[template.available()];

template.read(byteFileArray);

        pdfNewDocContext.setTemplate(byteFileArray);

        pdfNewDocContext.setData(WDInteractiveFormHelper.getContextDataAsStream(wdContext.nodeDataSource()));

IWDPDFDocument document = pdfNewDocContext.execute();

        IWDResource resource =

               WDResourceFactory.createCachedResource(document.getPDF(), "test.pdf", WDWebResourceType.PDF);

wdContext.currentContextElement().setPdfResource(resource);

} catch (Exception e) {

        this.msgMgr.reportException(e.getMessage());

}

Answers (0)