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
BedrockMission!

Learn More

View all

Sign in to view all badges

Regarding AEM Forms OutputService

Avatar

Avatar
Validate 10
Level 2
adeivasigamani
Level 2

Likes

4 likes

Total Posts

79 posts

Correct Reply

3 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Validate 10
Level 2
adeivasigamani
Level 2

Likes

4 likes

Total Posts

79 posts

Correct Reply

3 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 3
View profile
adeivasigamani
Level 2

15-10-2015

Hi Folks,

Using the Java API for AEM Forms output services (documentation available at http://helpx.adobe.com/aem-forms/6/javadocs/com/adobe/fd/output/api/OutputService.html) I am able to create the Postscript document. The problem I am facing is that, I do not know how to handle the Postscript returned to the browser. The returned postscript document when opened in the browser with window.open() gives a big text file as shown in the attached file.

I would like the browser to prompt to send this generated postscript to a printer.

The code that I used to generate the postscript is as follows

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException,
            IOException {
        String xmlData = null;
        try {
            Document indoc = new Document(
                    "/content/dam/formsanddocuments/NedbankInc/CurrentAccountForm.xdp/jcr:content/renditions/original");
            String contentRoot = "/content/dam/lcapplications/Myapp/1.0/Form/";
            Document pdfDoc = null;
            request.getResourceResolver();
            // Document doc = new Document(null);
            InputStream is = new ByteArrayInputStream(xmlData.getBytes());
            PrintedOutputOptions printOptions = new PrintedOutputOptions();
            printOptions.setCopies(1);
            printOptions.setContentRoot(contentRoot);
            printOptions.setLocale("in");
            PaginationOverride paginationOverride = PaginationOverride.simplex;
            printOptions.setPaginationOverride(paginationOverride);
            printOptions.setPrintConfig(PrintConfig.PS_PLAIN);
            log("The XDC URI is "+PrintConfig.PS_PLAIN.getXdcUri());
            pdfDoc = outputService.generatePrintedOutput(indoc, new Document(is), printOptions);
            pdfDoc.setContentType("application/postscript");
            IOUtils.copy(pdfDoc.getInputStream(), response.getOutputStream());
                pdfDoc.close();
                response.flushBuffer();
            log("Exit doGet method of DownloadPDFDocumentviaSOAPServlet");
        } catch (RepositoryException e) {
            log("RepositoryException occurred --- >  " + e.getLocalizedMessage());
            e.printStackTrace();
        } catch (OutputServiceException e) {
            log("OutputServiceException occurred --- >  " + e.getLocalizedMessage());
            e.printStackTrace();
        } 
    }

 

Do I need a postscript reader or a extension software to view the postscript as a printable file instead of some random code as obtained in the attached file.

 

Regards -

Ashok Deivasigamani

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 1
Level 2
nitinn18425437
Level 2

Like

1 like

Total Posts

16 posts

Correct Reply

7 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 1
View profile

Avatar
Boost 1
Level 2
nitinn18425437
Level 2

Like

1 like

Total Posts

16 posts

Correct Reply

7 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 1
View profile
nitinn18425437
Level 2

15-10-2015

Hi Ashok,

  This is happening because the code above does not set any content type for the response object and by default browser is considering the content type as text/plain and displaying it. 

   In the code above 

        pdfDoc.setContentType("application/postscript");

       you are setting content type on pdfDoc, instead you should set the content type on response

       Once you have set correct content type on response object, browsers will save the postscript file to disk from where it can be sent manually to printer. 

Thanks

Nitin

Answers (1)

Answers (1)

Avatar

Avatar
Validate 10
Level 2
adeivasigamani
Level 2

Likes

4 likes

Total Posts

79 posts

Correct Reply

3 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Validate 10
Level 2
adeivasigamani
Level 2

Likes

4 likes

Total Posts

79 posts

Correct Reply

3 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 3
View profile
adeivasigamani
Level 2

15-10-2015

Thanks Nithin,  Worked well on implementing your answer

Regards -

Ashok D