Pdfmake: Open fail in Microsoft Edge

Created on 6 Sep 2016  路  10Comments  路  Source: bpampuch/pdfmake

We have been unsuccessful in getting pdfmake to work in Microsoft Edge. We see only the following error under the F12 dev tools console and then a silent failure when the open or download method is called. Microsoft Edge 25.10586.0.0

SCRIPT5084: Invalid offset/length when creating typed array

browser bug

Most helpful comment

Any update on support for Edge?

All 10 comments

var fnTyped = {
arraySet: function (dest, src, src_offs, len, dest_offs) {
if (src.subarray && dest.subarray) {
dest.set(src.subarray(src_offs, src_offs+len), dest_offs); // Error being thrown here-- offset and len are all 0 but the len of src.subarray and dest.subarray is 2
return;
}
// Fallback to ordinary array
for (var i=0; i dest[dest_offs + i] = src[src_offs + i];
}
},

Microsoft Edge 25.10586.0.0

pdfMake.createPdf(docDefinition).open(); - open a blank page
pdfMake.createPdf(docDefinition).download(); - work's correctly

Any update on support for Edge?

Hi guys! some update for MS Edge?

Even if .Open() does not work, is there ANY way to display a PDF created with PDFMake in Edge? I've tried using .getDataUrl() to set the source of an <embed> tag as well as an <iframe> tag and neither of those work for me. Is there any other way to go about this?

I also tried different things, that all don't work with edge. It seems that Microsoft decided that data-urls are a source of evil and so completely dropped support for this. I really don't know what could be so problematic with data-urls, since every other browser i know supports them and makes it possible to display pdf-files or any other binary data in the browser (ie and edge are the same in this case, so "other" browser means "browser not from microsoft"). This problem seems to be known by microsoft since at least 2016 and they refuse to do anything about it, as far as i could figure out. Everything i read about it says that it is a security feature not to handle data-urls properly.

If anybody finds a way to enable pdfmake to show a pdf in edge, i would be very glad to hear about it. My webapp is currently not able to show the pdfs in edge as every other browser does. So i have to recommend chrome, firefox, opera or other browsers to my users.

If anyone still strugles with this issue, here is the fix:
in file /src/browser-extensions/pdfMake.js in line 112 change to this:

var urlCreator = window.URL || window.webkitURL;
var pdfUrl = urlCreator.createObjectURL(result);
win.location.href = pdfUrl;

into this:

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(blob, options.fileName + '.pdf');
} else {
    var urlCreator = window.URL || window.webkitURL;
    var pdfUrl = urlCreator.createObjectURL(blob);
    win.location.href = pdfUrl;
}

I'll try to contact with author and create PR for that.

I think this bug is inherited by: https://github.com/eligrey/FileSaver.js/issues/580
I use a similar workaround:

const pdf = pdfMake.createPdf(documentDefinition);

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    // Workaround until https://github.com/bpampuch/pdfmake/issues/693 is fixed.
    // which is inherited from https://github.com/eligrey/FileSaver.js/issues/580
    return new Promise((resolve) => {
        pdf.getBlob(blob => {
            window.navigator.msSaveOrOpenBlob(blob, `${fileBasename}.pdf`);
            resolve();
        });
    });
} else {
    return new Promise((resolve) => {
        pdf.download(`${fileBasename}.pdf`, resolve);
    });
}

In new Edge version 79+ works now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmatesic picture dmatesic  路  3Comments

Christian24 picture Christian24  路  3Comments

kamilkp picture kamilkp  路  3Comments

SummerSonnet picture SummerSonnet  路  3Comments

MathLavallee picture MathLavallee  路  3Comments