0

I am getting following response which is in json format

{"filename":"copyofabc.pdf","filedata":[37,80,68,70,45,49,46,53,13,10,37,-75,-75,-75,-75,13,10,49,32,48,32,111,98,106,13,10,60,60,47,84,121,112,101,47,67,97,116,97,108,111,103,47,80,97,103,101,115,32,50,32,48,32,82,47,76,97,110,103,40,101,110,45,73,78,41,32,47,83,116,114,117,99,116,84,114,101,101,82,111,111,11.....]}

enter code here


 var blob = new Blob($(this).attr('filedata'), {
                        type: 'application/pdf'
                    });
                    var objectURL = URL.createObjectURL(blob);
                    // Create an iframe to demonstrate it:
                    var iframe = document.createElement('iframe');
                    iframe.className = 'sample-iframe';
                    iframe.src = objectURL;
                    document.body.appendChild(iframe);

above code i am using to display pdf from byte array

1
  • Please post example if you have Commented Mar 29, 2017 at 13:26

2 Answers 2

6

This works for me on Chrome, but not on IE:

// base64DataFromWebAPI comes from a Web API, in the form of base 64 string
var pdfData = base64DataFromWebAPI;

var x = window.open();
var iframe = x.document.createElement('iframe')
iframe.width = '100%'
iframe.height = '100%'
iframe.frameBorder = 0
iframe.style = "border: 0"
iframe.src = "data:application/pdf;base64, " + pdfData
x.document.body.appendChild(iframe);

I got it from the following Stack Oveflow question: JsPDF - Not allowed to navigate top frame to data URL

Sign up to request clarification or add additional context in comments.

Comments

1

Using Chrome*, you can also simply paste the following code in the address bar:

data:application/pdf;base64, YOUR_PDF_DATA_HERE

It will open it in the included PDF viewer of the browser.

*didn't tested other browsers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.