如何在ajax响应中从字节流渲染pdf [英] How to render a pdf from bytestream in ajax response
问题描述
我正在开发一个移动应用程序.我们正在使用jquery-mobile.
我们可以选择查看或下载pdf格式的记录.我没有后端的控制权.我将以ajax响应的形式在json对象中获取pdf数据,我想读取该数据并以pdf格式显示.页面中也有下一个和上一个链接,因此我们需要在div中显示pdf.
var data = {
.... : ....,
.... : ....,
"pdfstream" : "KioqKioqKioqKioq......",
..... : ....
}
能够读取所有数据,但不确定如何读取该字节流并在页面中以pdf格式显示.
更新: 我的代码工作正常.但是从服务器获取的字节流是错误的.
var obj = $('<object type="application/pdf" width="100%" height="100%" border="2"></object>');
obj.attr('data','data:application/pdf;base64,'+bytestream);
$('#divContainer').append(obj);
在所有浏览器中的IE都可以正常工作.需要验证为什么它不能在IE中工作.
您尝试过使用此方法
http://mozilla.github.com/pdf.js/ >
此外,您可以访问以下链接,问题几乎相似:
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.
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
这篇关于如何在ajax响应中从字节流渲染pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!