Open pdf.js with a data URL in IE11

痴心易碎 提交于 2019-12-19 09:27:24

问题


I'm trying to use pdf.js for showing a document in a data URL on IE10. That is, something like this.

It works well with Firefox or Chrome, but in Internet Explorer 10 and 11, the interface is shown, but stays empty, and the document never loads.

I checked, compatibility.js is included in the renderer page (viewer.html), so IE support should be present.

EDIT: actually it's a security issue, as IE doesn't let to run a request of this type.

Thanks in advance,


回答1:


Ok, if someone runs to the same problem, I solved it by bypassing the lib's normal loading path, and as async5 advised, converting directly the data to a byte array.

That is, in viewer.js, add those lines under line 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;
  }

(the base64 to byte array code is the one posted by Codetoffel here)



来源:https://stackoverflow.com/questions/30894571/open-pdf-js-with-a-data-url-in-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!