javascript 如何在ajax响应中从字节流渲染pdf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16996743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to render a pdf from bytestream in ajax response
提问by sai sudhakar
I am working on a mobile application.we are using jquery-mobile.
我正在开发一个移动应用程序。我们正在使用 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.
我们可以选择查看或下载 pdf 格式的记录。我没有对后端的控制。我将在 json 对象中获取 pdf 数据作为 ajax 响应。我想读取该数据并以 pdf 格式显示。我的下一个和上一个链接也在页面中,所以我们需要在 div 中显示 pdf。
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.
我能够读取所有数据,但不确定如何读取该字节流并在页面中显示为 pdf。
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.
它在 IE 中期望的所有浏览器中都能正常工作。需要验证为什么它在 IE 中不起作用。
回答by Muntasim
Did you try with this
你有没有试过这个
http://mozilla.github.com/pdf.js/
http://mozilla.github.com/pdf.js/
Moreover you can visit the following link, the question is almost similar:
此外,您可以访问以下链接,问题几乎相似:
回答by user1889970
Don't show it in ajax show the pdf as source of an iframe then it will work
不要在ajax中显示它显示pdf作为iframe的源然后它会工作