How to visualize a pdf file from byte in ajax response

I am working on a mobile application. We are using jquery-mobile.

we have the ability to view or download pdf records. I have no control over the backend. I will get pdf data in json object as ajax response. I want to read this data and display it in pdf. I have the next and previous links on the page, so we need to display pdf in a div.

var data = { .... : ...., .... : ...., "pdfstream" : "KioqKioqKioqKioq......", ..... : .... } 

I can read all the data, but not sure how I can read this byte stream and display it as a PDF on the page.

UPDATE: My code is working fine. But the side stream that I get from the server is erroneous.

  var obj = $('<object type="application/pdf" width="100%" height="100%" border="2"></object>'); obj.attr('data','data:application/pdf;base64,'+bytestream); $('#divContainer').append(obj); 

its working tone in all browsers is expected in IE. You need to check why it does not work in IE.

+4
source share
2 answers

Have you tried with this

http://mozilla.github.com/pdf.js/

Alternatively, you can follow the link below, the question is almost the same:

How to display pdf stream in browser using javascript

+2
source

Do not show this in ajax show pdf as iframe source then it will work

+1
source

Source: https://habr.com/ru/post/1485151/


All Articles