streaming PDF from database to browser?


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

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


    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?


    Threaded Messages (4)

  2. Use iText[ Go to top ]


    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:

  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.
    6. read from the ByteArrayInputStream and write to the resp.getOutputStream() until everything is written
    7. close all streams
  5. thanks Jim!

    works perfectly :)