AssemblerService - how to access PDFs stored in AEM Repository for assembling
hello experts,
I want to merge multiple PDFs into single PDF using AssemblerService. Using Postman client I can pass PDF path like:
C:/test/first.pdf , C:/test/second.pdf
with code snippet:
String ddxFile = request.getParameter("ddx");
String pdf1 = request.getParameter("pdf1");
String pdf2 = request.getParameter("pdf2");
Map<String, Object> mapOfDocuments = new HashMap<String, Object>();
Document ddxDoc = new Document(new FileInputStream(ddxFile));
Document sourcePdfDoc1 = new Document(new FileInputStream(pdf1));
Document sourcePdfDoc2 = new Document(new FileInputStream(pdf2));
mapOfDocuments.put("pdf1", sourcePdfDoc1);
mapOfDocuments.put("pdf2", sourcePdfDoc2);
AssemblerOptionSpec optionSpec = new AssemblerOptionSpec();
optionSpec.setFailOnError(true);
// assembling of PDFs based on DDX rule
AssemblerResult assemblerResult = assemblerService.invoke(ddxDoc, mapOfDocuments, optionSpec);
Document outDoc = assemblerResult.getDocuments().get("output.pdf");
However questions is:
- if PDF are stored in AEM like:
- /content/dam/formsanddocuments/first.pdf
- /content/dam/formsanddocuments/second.pdf
- I am not able to pass PDF paths: crx:///content/dam/formsanddocuments/first.pdf and crx:///content/dam/formsanddocuments/second.pdf
- AssemblerService throws exception if we pass PDF paths like above?
Please let me know what are best ways to read the PDF from AEM repo. And if I need to use following code snippet to read the PDF from AEM repo?
Resource res = resolver.getResource(PDF_PATH );
Asset asset = res.adaptTo(Asset.class);
Resource pdf1 = asset.getOriginal();