How to render a pdf from bytestream in ajax response

2024/2/27 8:30:18

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.

Answer

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

http://en.ppmy.cn/q/42143.html

Related Q&A

Angular2 - inject into @Injectable

I have an Angular2 app with a service that is used for getting a data from an API. Following this example, I want to create a separate file which should contain some configuration data. My problem is t…

How to open a hidden div when a hash is on the URL?

Im using this javascript code to have a couple "show/hide" toggled divs on my site:<script language="javascript"> function toggledean() {var ele = document.getElementById(&qu…

Any real difference between window.prompt and prompt?

Just out of curiosity is there any difference between window.prompt and prompt in JavaScript.For one of the answers to my exam questions the teacher uses var yourName = window.prompt("Please enter…

Hide bootstraps .dropdown-backdrop, CSS only

Is it possible to hide Bootstraps .dropdown-backdrop element for a certain dropdown (not all on the page) by using CSS only?Ive determined that this is possible using Javascript, with JSFiddle here. H…

JavaScript / HTML5 audio: play mp3 file loaded by user via file selector in Android Chrome

I am trying to create a site where user can select a local audio file from their PC or tablet and (without uploading the file to the server) play that file using HTML5 audio tag (user is supposed to cl…

Get position of selected elements, not index of element in DOM

<div><h3>Heading one</h3><h3>Heading two</h3><h4>heading caption</h4><h3>Heading three</h3> </div>​I want to get the position of the element…

Streaming video with transparent pixels using webrtc

I am trying to capture html5 canvas using captureStream API which has drawings on it and play it using html5 video tag. Problem I am facing is, when I capture the stream and play it with in video tag I…

Find text in element that is NOT wrapped in html tags and wrap it with p

<div class="menu-content"><h3>Lorem Ipsum</h3>TEXT THAT NEEDS TO BE WRAPPED<ul><li>List Item 1</li></ul> </div>I got the code above (it gets ge…

Smooth css change transitions

Ive setup a jQuery function that changes the body background colour when a certain div comes into view, e.g. the body background colour is black, when #block-three (that contains black text), the body …

Google Tag Manager Parse Error. Primary Expression

I am trying to save this Custom Javascript Variable within Google Tag Manager and return this error each time:Error at line 2, character 4: Parse error. primary expression expectedvar prodID = function…