Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open fail in Microsoft Edge #693

Closed
dooziiinc opened this issue Sep 6, 2016 · 10 comments
Closed

Open fail in Microsoft Edge #693

dooziiinc opened this issue Sep 6, 2016 · 10 comments

Comments

@dooziiinc
Copy link

dooziiinc commented Sep 6, 2016

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

@dooziiinc
Copy link
Author

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<len; i++) {
dest[dest_offs + i] = src[src_offs + i];
}
},

@balkonrad
Copy link

Microsoft Edge 25.10586.0.0

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

@liborm85 liborm85 added the bug label Dec 18, 2016
This was referenced Dec 29, 2016
@liborm85
Copy link
Collaborator

reference: #800

@liborm85 liborm85 changed the title PDFMake: Open and Download fail in Microsoft Edge Open fail in Microsoft Edge Jul 31, 2017
@skendrot
Copy link

Any update on support for Edge?

@oceangravity
Copy link

Hi guys! some update for MS Edge?

@roddharris
Copy link

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?

@zreptil
Copy link

zreptil commented Nov 13, 2018

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.

@dwojtyca
Copy link

dwojtyca commented Jul 2, 2019

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.

@brabenetz
Copy link

brabenetz commented Nov 7, 2019

I think this bug is inherited by: eligrey/FileSaver.js#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);
    });
}

@liborm85
Copy link
Collaborator

liborm85 commented Jul 6, 2020

In new Edge version 79+ works now.

@liborm85 liborm85 closed this as completed Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants