This is an archived forum post. The information may be outdated. Contact us if you have any questions.

PDF Binary data

indaroma wrote on 2013-10-02:
I am new to this and very confused as to what to do the with PDF binary data that I receive back to a successful ajax request.

I created a getPdf.php that I perform a Ajax post request on, passing in the html data. getPdf gets the proper username and token and calls the appropriate function in the pdfcrowd php file. The pdf is set to be sent back as attachment. My jQuery code gets a success callback with the data that is binary PDF. Now I am stuck and no idea how to open that as a save as or download as in my browser.

Here is my ajax request:

jQuery.ajax({
type: 'POST',
url: "../scripts/getPdf.php",
data: {
htmldat: htmldat
},
success: function(data){
//console.log(data);
},
async:true,
error: function(data){
console.log('PDF fetch: failed' + data);
},
});

Thanks!
support wrote on 2013-10-02:
Hello,

I would recommend that getPdf.php stores the PDF on your server and returns an URL instead of binary data. You can then call
window.open(data.urlPdf);


It should be possible to render the PDF binary data using the data URI scheme. However this is not portable across browsers and has several potential disadvantages.
window.open("data:application/pdf," + escape(data.dataPdf));
indaroma wrote on 2013-10-03:
Thanks!!