admin管理员组文章数量:1400286
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
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);
Share Improve this question asked Mar 29, 2017 at 13:23 Ninad KulkarniNinad Kulkarni 5431 gold badge5 silver badges10 bronze badges 1above code i am using to display pdf from byte array
- Please post example if you have – Ninad Kulkarni Commented Mar 29, 2017 at 13:26
2 Answers
Reset to default 6This works for me on Chrome, but not on IE:
// base64DataFromWebAPI es 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
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
本文标签:
版权声明:本文标题:javascript - display byte array as pdf in browser i tried several options from stack overflow but it did not work for me - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744203425a2595075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论