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();
Views
Replies
Total Likes
var damFolder = "/content/dam/formsanddocuments/applicationforms/newsletter";
var strUrl = '/bin/listfoldercontents?damFolder='+damFolder;
I have followed a use case in the past, but I am not finding that link.
What Has been done in that case is, to pass the path of the folder on which pdf is stored to the servlet. Then you can use the below code to retrieve the files and play with them...
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
Resource resource = request.getResourceResolver().getResource(request.getParameter("damFolder"));
List < JsonObject > results = new ArrayList < > ();
resource.getChildren().forEach(child -> {
if (!JCR_CONTENT.equals(child.getName())) {
JsonObject asset = new JsonObject();
log.debug("##The child name is " + child.getName());
asset.addProperty("assetname", child.getName());
asset.addProperty("assetpath", child.getPath());
results.add(asset);
}
});
thanks for the response.
I want to know how can I access PDF stored in AEM without Asset API usages. For example if I read it from file system: C:/test/first.pdf , I can directly pass it in Document manager object
String pdf1 = request.getParameter("pdf1");
Document sourcePdfDoc1 = new Document(new FileInputStream(pdf1));
but if PDF is stored in AEM I am NOT able to read with simple path like - crx:///content/dam/formsanddocuments/first.pdf. However I can read with:
Resource res = resolver.getResource("crx:///content/dam/formsanddocuments/first.pdf");
Asset asset = res.adaptTo(Asset.class);
Resource pdf1 = asset.getOriginal();
InputStream pdfIS = pdf1.adaptTo(InputStream.class);
Document pdfDoc = new Document(pdfIS );
com.adobe.aemfd.docmanager.Document pdfDocument = new Document("crx:///content/dam/formsanddocument/samplepdf.pdf");
Hi ,
We are trying to assemple pdf using AssemblePdfService . I was able to create DDX with the same names of pdf also we are passing all the pdf in map as key value pair. I am not able to assemble the all the pdfs stored in DAM .
there are incorrect paths getting appended in the URL for the pdf while assembling.
Can anyone suggest.
Thanks
Will send you sample
When I try to read from AEM DAM, it is failing with following exception; on Document Object, and same works if supplied from Filesystem,
Document pdf1 = new Document("crx:///content/dam/formsanddocuments/common-forms/pdf1.pdf");
Document pdf2 = new Document("crx:///content/dam/formsanddocuments/common-forms/pdf2.pdf");
OperationException occurred: java.lang.RuntimeException: java.lang.CloneNotSupportedException: AEM-ASM-S00-011: The shared DOM named "{SharedStore name=pdf1 ID=124946548 idp=124946517 pdfDoc=null sharedData=null}" could not be cloned.
Do let me know if doing something wrong?
One more observation from my tests: able to read PDF using following code from within aem:
ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(serviceUserSession);
Resource res = resolver.getResource("/content/dam/formsanddocuments/common-forms/pdf1.pdf");
Asset asset = res.adaptTo(Asset.class);
Resource pdf = asset.getOriginal();
InputStream pdfIS = pdf.adaptTo(InputStream.class);
Document pdf1 = new Document(pdfIS);
Strange thing is that , it reads from /content/dam/formsanddocuments/common-forms/pdf1.pdf but *not* from /content/dam/PDF/Common-forms/pdf1.pdf.
Is there any reasoning behind it??? thanks.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies