Skip to Content
Author's profile photo Bernd Speckmann

Passing XDP template as stream

Especially when Adobe Document Services are not running on the same server as the WD application you should pass the xdp template source as stream instead of passing it as URL. If you are passing it as URL you will receive a rendering error.

This can be done as follows:

String templateUrl = null;
ByteArrayOutputStream templateStream = null;
...
templateUrl = WDURLGenerator.getPublicResourcePath(otherPart, "My_InteractiveForm.xdp");
InputStream template = new FileInputStream(templateUrl);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
              int nRead;
              byte[] data = new byte[16384];
              while ((nRead = template.read(data, 0, data.length)) != -1) {
                        buffer.write(data, 0, nRead);
              }
              buffer.flush();
              templateStream = buffer;
.....
IWDPDFDocumentHandler pdfDocumentHandler = WDPDFDocumentFactory.getDocumentHandler();
IWDPDFDocumentCreationContext pdfDocumentCreationContext = pdfDocumentHandler.getDocumentCreationContext();
.....
pdfDocumentCreationContext.setTemplate(templateStream);

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.