0

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?

Carlos
  • 23
  • 1
  • 4
  • Do you want your app to handle displaying the PDF or will you have a separate PDF reader program deal with that? – ameed Jul 24 '13 at 16:58
  • 2
    Also, from what I understand, you want to take bytes of a PDF from a network connection and convert them into a PDF on the local workstation. Is that correct? – ameed Jul 24 '13 at 17:05

2 Answers2

1

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.

Community
  • 1
  • 1
Paolo Casciello
  • 7,982
  • 1
  • 43
  • 42
  • Beware: I'm pretty sure that IE, being its usual IE-ish self, disapproves of data-urls for all but a few types, not including PDF. Source: [MSDN](http://msdn.microsoft.com/en-us/library/cc848897%28VS.85%29.aspx) – ameed Sep 02 '13 at 01:56
0

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!

ameed
  • 1,132
  • 6
  • 25
  • I was using an iframe to show the PDF, but on IE is not working ... Any ideas about how to render base64 bytes? – Carlos Jul 26 '13 at 17:48