4

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

we have an option to view or download the records in pdf format. I dont have the control on backend. I will get the pdf data in json object as an ajax response.I want to read that data and display in a pdf. I have next and previous links are also in the page so we need to display pdf in a div.

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

am able to read all the data but not sure how can i read that bytestream and display as an pdf in the page.

UPDATE: My code is working fine. But the bytestream which am getting from server is wrong.

    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 fine in all browsers expect in IE. Need to verify why its not working in IE.

sai sudhakar
  • 204
  • 1
  • 2
  • 8

2 Answers2

2

Did you try with this

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

Moreover you can visit the following link, the question is almost similar:

How to display a PDF stream in a browser using javascript

Community
  • 1
  • 1
Muntasim
  • 6,689
  • 3
  • 46
  • 69
  • Thanks for the reply. I tried that pdf.js that is expecting the pdf stream directly from response by setting the response header. But am getting a json object. var output = {"downloadpdf":"KioqKioqKioqKioq.............."} and i tried the example mentioned in the below link. Its displaying all my bytestream in the urlbar and also pdf is corrupted. Its throwing an error like "Failed to load pdf document". – sai sudhakar Jun 08 '13 at 20:40
1

Don't show it in ajax show the pdf as source of an iframe then it will work

user1889970
  • 726
  • 1
  • 8
  • 12