AnsweredAssumed Answered

Display dynamic PDF directly in the browser

Question asked by ericfrigot on Mar 23, 2012
Latest reply on Mar 23, 2012 by ericfrigot
Hi All,

I am trying to write a JAVA Web Script to display generated PDF in the browser. Here is the code :


public class MyPDFWebScript extends AbstractWebScript {

   @Override
   public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
         res.setContentType("application/pdf");
         res.setContentEncoding(null);
         res.addHeader("Content-Disposition", "inline;filename=12F002340.PDF");
         res.addHeader("Content-Length", Integer.toString(content.length));
         res.addHeader("Pragma", "no-cache");

         res.getWriter().write(new String(content)); // Here I write my PDF content
   }
}

When I write the content byte array into a file, I can correctly open and view the PDF
When I write the same content in the WebScriptResponse I get an empty PDF

I think something is missing into my code, but I don't know what.

Somebody could help me ?

Thanks,
Eric

Outcomes