My requirement is to force the system to open the PDF file without storing in server or client system. I am using java, jsf, iText. But I've not succeeded so far. Any help?
-
2That is trivial on the server side, but what kind of clients are we talking about? Web browsers and their plugged-in PDF viewers? You can hardly prevent them storing temporary copies somewhere. – mkl Oct 16 '14 at 12:31
-
Server-side, you can create the PDF file in a stream (i.e. no PDF file will be stored in the server's filesystem). However, unless you set up some DRM system, the file will have to be downloaded client-side in order to be viewed (even if it's downloaded in a temp folder, it'll be on the client's filesystem anyway). – Alexis Pigeon Oct 16 '14 at 12:31
-
Need to open pdf file browser or acrobat reader. not save in server or using predefine file path. – Skyfall Oct 16 '14 at 12:47
1 Answers
This question has already been answered a day ago here: How to convert pdfstamper to byte array
I didn't mark your question as duplicate, because your question and that question may seem different at first sight, but the answer to both questions is identical:
See for instance the FormServlet example where it says:
// We create an OutputStream for the new PDF
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Now we create the PDF
PdfStamper stamper = new PdfStamper(reader, baos);
Then later in the example, we do this:
// We write the PDF bytes to the OutputStream
OutputStream os = response.getOutputStream();
baos.writeTo(os);
As you can see: we do not store the PDF using a FileOutputStream
(no file is stored on the server), but we store the file in memory using a ByteArrayOutputStream
. We then write the bytes to the OutputStream
of the response object.
This example is taken from a book that also contains a JSP example: http://itextpdf.com:8180/book/helloworld.jsp
However, the book lists a substantial number of reasons why it's a bad idea to use JSP to create PDF. As a JSP developer, you know that JSP should never be used to create files in a binary format. PDFs are binary files, hence: you should write a Servlet to create a PDF, not a JSP file.

- 1
- 1

- 75,994
- 9
- 109
- 165