Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

AEM as a Cloud Service Tutorials - Merge data with the XDP template | AEM Community Blog Seeding




AEM as a Cloud Service Tutorials - Merge data with the XDP template by Adobe Docs


Make the POST call
The next step is to make an HTTP POST call to the endpoint with the necessary parameters. The template and the datafiles are provided as resource files. Properties of the generated pdf are specified via the option’s parameter in the request.The property embedFonts is used to embed custom fonts in the generated pdf.Please follow this documentation to deploy custom fonts to your Forms cloud instance. The properties are specified in the options.json resource file. Since, the end point has token based authentication we pass the Access Token in the request header.

The following code was used to generate pdf by merging data with the template

public class DocumentGeneration
public String SAVE_LOCATION = "c:\\aspire1";
public void mergeDataWithXdpTemplate(String postURL)
HttpPost httpPost = new HttpPost(postURL);
CredentialUtilites cu = new CredentialUtilites();
String accessToken = cu.getAccessToken();
httpPost.addHeader("Authorization", "Bearer " + accessToken);
ClassLoader classLoader = DocumentGeneration.class.getClassLoader();
URL templateFile = classLoader.getResource("templates/custom_fonts.xdp");
File xdpTemplate = new File(templateFile.getPath());
URL url = classLoader.getResource("datafiles");
File files[] = new File(url.getPath()).listFiles();
for (int i = 0; i < files.length; i++) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
ContentType strContent = ContentType.create("text/plain", Charset.forName("UTF-8"));
builder.addBinaryBody("data", files[i]);
builder.addBinaryBody("template", xdpTemplate);
try {
HttpEntity entity = builder.build();
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = httpclient.execute(httpPost);
InputStream generatedPDF = response.getEntity().getContent();
byte[] bytes = IOUtils.toByteArray(generatedPDF);
File saveLocation = new File(SAVE_LOCATION);
if (!saveLocation.exists()) {
File outputFile = new File(SAVE_LOCATION+File.separator+files[i].getName().replace("xml", "pdf"));
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
} catch (Exception e) {
System.out.println("The error is " + e.getMessage());

System.out.println("Done generating " + files.length + " files");



Read Full Blog

AEM as a Cloud Service Tutorials - Merge data with the XDP template


Please use this thread to ask the related questions.

Kautuk Sahni
0 Replies