0

I use ajax to call function from server, it returns byte[] of the pdf. How can I display it in browser in readable form in new window?
I can print out the bytecode in the console, but how can I visualize it in browser? I don't want to download the pdf.

I'm not using PDF.js. I only have JS and JQuery.

Rana Ghosh
  • 4,514
  • 5
  • 23
  • 40
Marko Taht
  • 1,448
  • 1
  • 20
  • 40
  • 1
    Possible duplicate of [Pdf.js: rendering a pdf file using a base64 file source instead of url](http://stackoverflow.com/questions/12092633/pdf-js-rendering-a-pdf-file-using-a-base64-file-source-instead-of-url) – Webbanditten May 04 '17 at 08:20
  • Is there a reason for not using PDF.js? Otherwise you need to convert your byte[] to "data:application/pdf;base64," (does not work on IE for large pdfs) or `URL.createObectURL(new Blob(` which is not supported on older browsers. – async5 May 04 '17 at 17:12

1 Answers1

-1

You should set Content-Type: application/pdf for return page. Browsers that has PDF Reader plugin it will open it, browsers that didn't have plugin will propose to download as PDF file

Alexey Samara
  • 131
  • 1
  • 13
  • Ok.... im using grails. ajax sends request to controller. controller constructs the byte[] of the pdf. Then sends it back to the JS. what next, how do i put it on the page. where do i put it ? – Marko Taht May 04 '17 at 12:28
  • I hope, that link will be useful for you: – Alexey Samara May 04 '17 at 12:32