Month: June 2017

AEM form 6.2 OutPut Service to generate PDF using XDP Template

Sample JSP code to generate PDF using XDP Template and Data generated from Mobile HTML.

<%@include file=”/libs/foundation/global.jsp”%><%@include file=”/libs/foundation/global.jsp”%><%@ page session=”false” %><%@ page import=”org.apache.sling.api.resource.ResourceResolver”%><%@ page import=”java.io.*” %><%@ page import=”javax.xml.*” %><%@ page import=”org.w3c.dom.*” %>

<%
String UID = request.getParameter(“UID”);
Resource resTemplate= resourceResolver.getResource(“/content/dam/formsanddocuments/xxx-ria/Accounts_and_Advisors1.xdp/jcr:content/renditions/original”);javax.jcr.Node ntFileNodeTemplate = resTemplate.adaptTo(javax.jcr.Node.class);javax.jcr.Node ntResourceNodeTemplate = ntFileNodeTemplate.getNode(“jcr:content”);InputStream xdbis = ntResourceNodeTemplate.getProperty(“jcr:data”).getBinary().getStream();com.adobe.aemfd.docmanager.Document xdpDocument = new com.adobe.aemfd.docmanager.Document(xdbis);

Resource resData= resourceResolver.getResource(“/content/usergenerated/content/forms/XFA-xxx/Account/”+UID);javax.jcr.Node ntFileNodeData = resData.adaptTo(javax.jcr.Node.class);javax.jcr.Node ntResourceNodeData = ntFileNodeData.getNode(“jcr:content”);InputStream dataIs = ntResourceNodeData.getProperty(“jcr:data”).getBinary().getStream();com.adobe.aemfd.docmanager.Document dataDocument = new com.adobe.aemfd.docmanager.Document(dataIs);

com.adobe.fd.output.api.OutputService outputService = sling.getService(com.adobe.fd.output.api.OutputService.class);if(outputService ==null)                 {
System.out.println(“The output service is null..111…”);}com.adobe.fd.output.api.PDFOutputOptions pdfOptions = new com.adobe.fd.output.api.PDFOutputOptions();pdfOptions.setAcrobatVersion(com.adobe.fd.output.api.AcrobatVersion.Acrobat_11);com.adobe.aemfd.docmanager.Document generatedDocument = outputService.generatePDFOutput(xdpDocument,dataDocument,pdfOptions);//generatedDocument.copyToFile(new java.io.File(“c:/pg.pdf”));response.setContentType(“application/pdf”);byte[] bytes = com.google.common.io.ByteStreams.toByteArray(generatedDocument.getInputStream());//response.setContentLength(bytes.length);
response.getOutputStream().write(bytes, 0, bytes.length);response.getOutputStream().flush();System.out.println(“The output service is null..222222222…”);

%>