Open pdf.js with a data URL in IE11

后端 未结 1 1008
死守一世寂寞
死守一世寂寞 2021-01-14 09:41

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

相关标签:
1条回答
  • 2021-01-14 10:35

    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)

    0 讨论(0)
提交回复
热议问题