Regarding AEM Forms OutputService



Hi Folks,

Using the Java API for AEM Forms output services (documentation available at 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 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(
            String contentRoot = "/content/dam/lcapplications/Myapp/1.0/Form/";
            Document pdfDoc = null;
            // Document doc = new Document(null);
            InputStream is = new ByteArrayInputStream(xmlData.getBytes());
            PrintedOutputOptions printOptions = new PrintedOutputOptions();
            PaginationOverride paginationOverride = PaginationOverride.simplex;
            log("The XDC URI is "+PrintConfig.PS_PLAIN.getXdcUri());
            pdfDoc = outputService.generatePrintedOutput(indoc, new Document(is), printOptions);
            IOUtils.copy(pdfDoc.getInputStream(), response.getOutputStream());
            log("Exit doGet method of DownloadPDFDocumentviaSOAPServlet");
        } catch (RepositoryException e) {
            log("RepositoryException occurred --- >  " + e.getLocalizedMessage());
        } catch (OutputServiceException e) {
            log("OutputServiceException occurred --- >  " + e.getLocalizedMessage());


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)



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 


       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.