Carlos
Carlos

Reputation: 23

Displaying on HTML a byte array (PDF file) returned as JSON

I have a PDF file that's being read through Java and returned as a byte array in a JSON response.

I want to find a way to parse those bytes from the PDF file using:

FileUtil.getFileBytes(fileToRead)

on the client side. Is there any way to render and display the PDF?

I know that I can put the file on a public server, but this may change based on user configuration, so I want to read the PDF on Java side and render the bytes on client side using Javascript or any jQuery plugin.

Any thoughts?

Upvotes: 0

Views: 5966

Answers (2)

ameed
ameed

Reputation: 1160

If you want to read bytes from a network connection and make them into a PDF, you could use Java I/O InputStreams and OutputStreams.

First, read in the bytes of the file into a byte array using an InputStream.

Then, write these out into a new file with the FileOutputStream.

Finally, invoke a PDF reader app to display the PDF. There should be a few out there.

I know this answer is a bit vague, and sorry if I misinterpreted your question, but I hope that this gave you a few pointers!

Upvotes: 0

Paolo Casciello
Paolo Casciello

Reputation: 8202

Look at inlining content in html. Have a look at this example inlining an image: Embedding Base64 Images

If the browser knows how to show it (maybe only chrome) it will show.

Upvotes: 1

Related Questions