streaming PDF from database to browser?

Discussions

Web tier: servlets, JSP, Web frameworks: streaming PDF from database to browser?

  1. streaming PDF from database to browser? (4 messages)

    Hi,

    I need to display pdf files (stored as blob datatypes in Oracle 8i) to client in a web browser. The pdf-stream should be generated in a servlet. Can anyone recommend some examples / tutorials / documentation about this process?

    thanks..

    Threaded Messages (4)

  2. Use iText[ Go to top ]

    Hello,

    just use iText the API to generate PDF Documents on the flow from Java applications. You can use it also in Servlet to create a PDF Stream. Here is an example to use iText in a servlet:
    http://itext.sourceforge.net/tutorial/general/webapp/index.html#MyJavaServer

    Ciao,
    Soner
  3. I just went through evaluating iText to XSL/FO for generating my PDF and in my case I needed a very pretty PDF. Therefore I found XSL/FO to be my solution. However I would have used iText had the design of the PDF been easier.
  4. It sounds like you already have your BLOBs stored in the DB, so iText, etc would be a waste of time because the PDFs are already genereated.


    Here is a recipe for you to consider...

    1. run a query along the lines of "select bloblcolumn from sometable"
    2. use the ResultSet.getBlob() method to get the Blob object
    3. the use the Blob.getBytes() to get a byte array of the PDF
    4. create a ByteArrayInputStream with this byte array
    5. set the content of the response object to PDF i.e.
    resp.setContentType("application/vnd.ms-excel");
    resp.setContentLength(arrayLength);
    6. read from the ByteArrayInputStream and write to the resp.getOutputStream() until everything is written
    7. close all streams
  5. thanks Jim!

    works perfectly :)