在二进制字符串或base64中的Internet Explorer 11中显示嵌入的PDF [英] Display embedded PDF in Internet Explorer 11 from binary string or base64

查看:165
本文介绍了在二进制字符串或base64中的Internet Explorer 11中显示嵌入的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有第三方服务向我发送二进制字符串或base64编码的PDF文件。是否有可能使用二进制字符串或base64编码显示嵌入在IE 11中的PDF。



从SO和其他论坛,我得出结论,IE 11仅支持数据uri对于图像而不是PDF(我可能是错的),这就排除了base64。所以剩下的唯一选择是从二进制字符串显示。我在Node应用程序中使用它,但我没有选择先将检索到的文件保存到Node服务器并使用静态URL。



请让我知道在IE 11中是可以实现的。



目前我正在尝试使用 https://github.com/pipwerks/PDFObject 。对于Chrome& Firefox,我检索base64文件,并使用上面的软件包嵌入它,并且工作正常。 解决方案

此解决方案使用 pdf.js



渲染base64 PDF时的关键点使用PDF.js库




  • 首先使用atob解码它

  • 然后使用上面的解码对Uint8Array进行初始化data



摘自express-pdfjs / scripts / App.js



 let options = {
方法:'GET',
uri:'http:// localhost:5000 / getBase64Pdf',
resolveWithFullResponse:true $ b $($ response)=> {
if(response.statusCode!== 200){
console.error('http)
rp(options)
.then不是200但是:',response.statusCode)
} else {
console.info('connected successfully:'+ response.statusCode)
let pdfData = atob(respon se.body)
let uint8ArrayPdf = new Uint8Array(pdfData.length)
for(let i = 0;我< pdfData.length; i ++){
uint8ArrayPdf [i] = pdfData.charCodeAt(i)
}
let pdfjsframe = document.getElementById('pdfViewer');
pdfjsframe.contentWindow.PDFViewerApplication.open(uint8ArrayPdf);

))

pdfViewer是index.html中的一个iframe, p>

 < iframe id =pdfViewersrc =http:// localhost:3000 / express-pdfjs / pdfViewer / web / viewer .htmlheight =1600width =850/> 




请使用React on client $ b $找到一个示例实现b side
@ https://github.com/rohanray/so-pdf-base64



There is a 3rd party service which sends me a PDF file in either binary string or base64 encoded. Is there any possibility to display the PDF embedded in IE 11 using either binary string or base64 encoded.

From SO and other forums, I concluded that IE 11 supports data uri only for images and not PDF (I might be wrong) which rules out base64. So the only option left is to display from binary string. I am using it in a Node App but I do not have the option to first save the retrieved file to Node server and use static URL.

Please let me know if above is achievable in IE 11.

Currently I'm trying to use npm package of https://github.com/pipwerks/PDFObject. For Chrome & Firefox, I retrieve the base64 file and embed it using the above package and works fine.

解决方案

This solution uses pdf.js

Keypoint in rendering a base64 PDF using PDF.js library

  • First decode it using atob
  • Then initializing a Uint8Array using above decoded data

Abstract from express-pdfjs/scripts/App.js

let options = {
      method: 'GET',
      uri: 'http://localhost:5000/getBase64Pdf',
      resolveWithFullResponse: true
    }
rp(options)
  .then((response) => {
    if (response.statusCode !== 200) {
      console.error('http not 200 but : ', response.statusCode)
    } else {
      console.info('connected successfully : ' + response.statusCode)
      let pdfData = atob(response.body)
      let uint8ArrayPdf = new Uint8Array(pdfData.length)
      for (let i = 0; i < pdfData.length; i++) {
        uint8ArrayPdf[i] = pdfData.charCodeAt(i)
      }
      let pdfjsframe = document.getElementById('pdfViewer');
      pdfjsframe.contentWindow.PDFViewerApplication.open(uint8ArrayPdf);
    }
  })

pdfViewer is an iframe in index.html

<iframe id="pdfViewer" src="http://localhost:3000/express-pdfjs/pdfViewer/web/viewer.html" height="1600" width="850" />

Please find a sample implementation for this using React on client side @ https://github.com/rohanray/so-pdf-base64

这篇关于在二进制字符串或base64中的Internet Explorer 11中显示嵌入的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆