Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

How to assemble multiple XDP fragments using the Java API


Level 2

Hi All,


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;

Below is my code;

private Document assemblerService(SlingHttpServletRequest request)
{"--------------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=\"\">");
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>"); is = new;
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

//Create an AssemblerOptionsSpec object
AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();

//Submit the job to Assembler service
AssemblerResult jobResult = null;
try {
jobResult = assemblerClient.invokeDDX(myDDX,inputs,assemblerSpec);
catch (Exception e1) {
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);
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: 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] service: Uncaught Throwable



1 Reply


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