Converting images to PDF using AEM services | Community
Skip to main content
sebastian_wilhe
Level 2
September 8, 2016

Converting images to PDF using AEM services

  • September 8, 2016
  • 3 replies
  • 6097 views

Hello!

For our projects at the Finanzinformatik in Frankfurt we need to convert PDF documents with
barcode to an image format and back to PDF for automated comparison. Converting PDF to image is working fine.

But how can an image be converted into a PDF document using AEM services?

I have been researching ways with AssemblerService by calling invoke method with DDX
and GeneratePdfService, but it only seems to be supported for some office document types.

Is there a solution for converting images into PDF, perhaps with a little code example?

That would be very helpful!

Thanks!

Sebastian Wilhelm

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

kautuk_sahni
Community Manager
Community Manager
September 8, 2016

I have asked internal team to help you in this.

~kautuk

Kautuk Sahni
kautuk_sahni
Community Manager
Community Manager
September 8, 2016

Hi 

There is a documentation for Image to PDF of GeneratePDFService :- http://help.adobe.com/en_US/AEMForms/6.1/AdminHelp/WS92d06802c76abadb-5145d5d12905ce07e7-7ff7.2.html

For other information,  let the internal team to respond.

~kautuk

Kautuk Sahni
Level 8
September 8, 2016

The javadoc is here for the API

The following is sample JSP code

            ToImageOptionsSpec spec = new com.adobe.fd.cpdf.api.ToImageOptionsSpec();


        System.out.println("$$$$$$$Successfully set  the image spec");
spec.setImageConvertFormat(ImageConvertFormat.JPEG);
        spec.setGrayScaleCompression(GrayScaleCompression.Low);
        spec.setColorCompression(ColorCompression.Low);
        spec.setFormat(JPEGFormat.BaselineOptimized);
        spec.setRgbPolicy(RGBPolicy.Off);
        spec.setCmykPolicy(CMYKPolicy.Off);
        spec.setColorSpace(ColorSpace.RGB);
        spec.setResolution("72");
        spec.setMonochrome(MonochromeCompression.None);
        spec.setFilter(PNGFilter.Sub);
        spec.setInterlace(Interlace.Adam7);
        spec.setTileSize(180);
        spec.setGrayScalePolicy(GrayScalePolicy.Off);
ConvertPdfService convertPdfService = sling.getService(ConvertPdfService.class);
System.out.println("$$$$$Got Convert PDF Service");
     System.out.println("Inside dummy for PDF G");
    System.out.println("The ocr value is ..."+request.getParameter("ocr"));
    SlingScriptHelper scriptHelper = bindings.getSling();
    RequestParameter inputFileParam = scriptHelper.getRequest().getRequestParameter("inputDoc");
    String convert = request.getParameter("Convert");
    System.out.println("The value of convert "+convert);

        InputStream inputDocStream = null;
        String fileName = FilenameUtils.getName(inputFileParam.getFileName());
        inputDocStream = inputFileParam.getInputStream();
         com.adobe.aemfd.docmanager.Document uploadedDocument = new com.adobe.aemfd.docmanager.Document(inputDocStream);

        java.util.List allImages = convertPdfService.toImage(uploadedDocument,spec);

        System.out.println("@@@@@@@The number of images I got was ...."+allImages.size());

        System.out.println("$$$$ Converted the PDF to Images&&&&&&");

sebastian_wilhe
Level 2
September 9, 2016

Thank you for the example code, BUT like I wrote above, the conversion PDF->IMAGE already works fine.

The problem is the direction IMAGE->PDF !!!

 

Do you have a working example for this case, too?

Thanks and Regards

Sebastian

smacdonald2008
Level 10
September 9, 2016

According to the Javadocs:

https://helpx.adobe.com/aem-forms/6-2/javadocs/com/adobe/fd/cpdf/api/ConvertPdfService.html

This is not a supported use case using this API. 

However - this is the API that will convert an image into a PDF:

https://helpx.adobe.com/aem-forms/6-2/javadocs/com/adobe/pdfg/service/api/GeneratePDFService.html

Here is an older Javadoc for this API with more detail: 

http://help.adobe.com/en_US/livecycle/9.0/programLC/javadoc/com/adobe/livecycle/generatepdf/client/GeneratePdfServiceClient.html#createPDF2(com.adobe.idp.Document, java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.adobe.idp.Document, com.adobe.idp.Document)

Hope this helps.