Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to assemble multiple XDP fragments using the Java API

Avatar

Level 2

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.ht...

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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-experienc...



Arun Patidar

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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-experienc...



Arun Patidar

Avatar

Level 2
Thank you @Deleted Account. I will move this thread as suggested.