2015-06-17 80 views
1

我试图使用pdf.js在IE10上的数据URL中显示文档。那就是,something like this在IE11中打开带有数据URL的pdf.js

它适用于Firefox或Chrome,但在Internet Explorer 10和11中显示界面,但保持为空,并且文档不会加载。

我检查过,compatibility.js包含在渲染器页面(viewer.html)中,所以IE支持应该存在。

编辑:实际上这是一个安全问题,因为IE不允许运行这种类型的请求。

由于提前,

+1

转换数据的URL字节数组并使用打开使用PDFViewerApplication.open? – async5

+1

请记住,IE浏览器也会截断长URL,因此您的base64编码的PDF可能会损坏。 – async5

回答

1

好吧,如果有人运行到同样的问题,我解决它绕过的lib的正常加载路径,并作为async5建议,直接将数据转换为一个字节数组。

即,在viewer.js,添加下线6856的那些行:

if (file && file.lastIndexOf('data:', 0) === 0) { 
     // data: url-scheme. we will load those with direct conversion to byte array 

     function convertDataURIToBinary(dataURI) { 
      var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length; 
      var base64 = dataURI.substring(base64Index); 
      var raw = window.atob(base64); 
      var rawLength = raw.length; 
      var array = new Uint8Array(new ArrayBuffer(rawLength)); 

      for(var i = 0; i < rawLength; i++) { 
       array[i] = raw.charCodeAt(i); 
      } 
      return array; 
     } 

     // PDFViewerApplication.setTitleUsingUrl(file); 
     PDFViewerApplication.open(convertDataURIToBinary(file), 0); 

     return; 
    } 

(以base64为字节阵列码是一个张贴由Codetoffel here

+0

这是哪种PDFViewerApplication?... adobe reader? – AkshayJ

+0

不,这是一个内部类pdf.js –

+0

没有任何其他的解决方法,使用pdf.js只是使其在IE11中工作?...我的意思是这太多的开销,只是在IE支持:( – AkshayJ