Displaying Blob PDF in Edge/IE11

后端 未结 2 1797
既然无缘
既然无缘 2020-12-10 14:58

I have a django app (from which I get some html as a client), and a base64-encoded PDF which needs to be displayed. I\'ve tried multiple approaches, which work as expected i

相关标签:
2条回答
  • 2020-12-10 15:14

    A cross-browser workaround to have an iframe of PDF.js load a blob of a PDF via the iframe URI.

    An example of a standard usage case blob URI:

    /viewer.html?file=blob:19B579EA-5217-41C6-96E4-5D8DF5A5C70B
    

    File viewer.js:

    within function webViewerOpenFileViaURL:

    change line from:

    if (file && file.lastIndexOf('file:', 0) === 0) {
    

    to:

    if (file && file.lastIndexOf('file:', 0) === 0 || file && file.lastIndexOf('blob:', 0) === 0) {
    

    And to further stop the viewer from breaking when the "origin" is behaving in an IE 11/Edge manner:

    within function validateFileURL:

    change line from:

    if (fileOrigin !== viewerOrigin) {
    

    to:

    if (fileOrigin != "null" && fileOrigin !== viewerOrigin) {
    

    Now FF, Chrome, IE 11, and Edge all display the PDF in a viewer in the iframe passed via standard blob URI in the URL.

    0 讨论(0)
  • 2020-12-10 15:20

    Blob URLs will not work in IE11 due to security restrictions!

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