How to assemble multiple XDP fragments using the Java API | Community
Skip to main content
New Participant
January 14, 2021
Solved

How to assemble multiple XDP fragments using the Java API

  • January 14, 2021
  • 1 reply
  • 1290 views

Hi All,

Greetings!

I am trying to assemble multiple fragments to create a one master xdp file so that I can use the same to generate the PDF.

I have tried the following documentation for the same;

https://helpx.adobe.com/experience-manager/6-3/forms/developing/assembling-multiple-xdp-fragments.html

Below is my code;

private Document assemblerService(SlingHttpServletRequest request) { log.info("--------------inside assemblerService method------------------"); ServiceClientFactory scf = scfProvider.getDefaultServiceClientFactory(); AssemblerServiceClient assemblerClient = new AssemblerServiceClient(scf); StringBuffer ddxDoc = new StringBuffer(); ddxDoc.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); ddxDoc.append("<DDX xmlns=\"http://ns.adobe.com/DDX/1.0/\">"); ddxDoc.append("<XDP result=\"tuc018result.xdp\">"); ddxDoc.append("<XDP source=\"tuc018_template_flowed.xdp\">"); ddxDoc.append("<XDPContent insertionPoint=\"ddx_fragment\" source=\"frgTest.xdp\" fragment=\"frgTest\" required=\"false\"/>"); ddxDoc.append("</XDP></XDP></DDX>"); java.io.InputStream is = new java.io.ByteArrayInputStream(ddxDoc.toString().getBytes()); com.adobe.idp.Document myDDX = new com.adobe.idp.Document(is); ResourceResolver resourceResolver = request.getResourceResolver(); String xdpDoc1 = "/content/dam/xdps/frgTest.xdp"; Resource res = resourceResolver.getResource(xdpDoc1); Asset asset = res.adaptTo(Asset.class); Resource original = asset.getOriginal(); InputStream xdpIS = original.adaptTo(InputStream.class); com.adobe.idp.Document frgXdpDoc = new com.adobe.idp.Document(xdpIS); //Create a Map object to store the PDF source documents Map inputs = new HashMap(); //Place two entries into the Map object inputs.put("frgTest",frgXdpDoc); //Create an AssemblerOptionsSpec object AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); assemblerSpec.setFailOnError(true); //Submit the job to Assembler service AssemblerResult jobResult = null; try { jobResult = assemblerClient.invokeDDX(myDDX,inputs,assemblerSpec); } catch (Exception e1) { e1.printStackTrace(); } java.util.Map allDocs = jobResult.getDocuments(); //Retrieve the resulting PDF document from the Map object Document outDoc = null; //Iterate through the map object to retrieve the resulting PDF document for (Iterator i = allDocs.entrySet().iterator(); i.hasNext();) { // Retrieve the Map object's value Map.Entry e = (Map.Entry)i.next(); Object o = e.getValue(); if (o instanceof Document) { //Cast the Object to a Document outDoc = (Document)o; } } return outDoc; }

Here in this code, I am using one xdp fragment to test if it can return a master xdp doc.

Please check and let me know if I am missing anything. Using this code I am getting following error;

14.01.2021 17:04:43.780 *ERROR* [0:0:0:0:0:0:0:1 [1610661875760] GET /bin/aem/api/generate/pdf/preview HTTP/1.1] com.aem.code.core.servlets.CreatePDF Error OCCURRED Exception: ALC-DSC-099-000: com.adobe.idp.dsc.DSCRuntimeException: java.net.ConnectException: Connection refused: connect
14.01.2021 17:04:43.781 *ERROR* [0:0:0:0:0:0:0:1 [1610661875760] GET /bin/aem/api/generate/pdf/preview HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

I would suggest moving this thread to dedicated AEM Forms community to get a faster response

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-forms/ct-p/adobe-experience-manager-forms-community

1 reply

arunpatidar
arunpatidarAccepted solution
New Participant
February 17, 2021

Hi,

I would suggest moving this thread to dedicated AEM Forms community to get a faster response

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-forms/ct-p/adobe-experience-manager-forms-community

Arun Patidar
ramandeepAuthor
New Participant
February 18, 2021
Thank you @1464355. I will move this thread as suggested.