When downloading a PDF in IE10, e.g.:
var pdf = pdfMake.createPdf(docDefinition);
pdf.download();
The following error is thrown on the download function call:
SCRIPT5022: InvalidStateError
This error originates from this line in src/browser-extensions/pdfMake.js:
saveAs(new Blob([result], {type: 'application/pdf'}), defaultFileName);
From debugging in the browser, I can see that the problem occurs when trying to execute this expression:
new Blob([result])
The Blob constructor is available and defined in IE10 and I've successfully tried creating simpler Blobs at the same point in the code.
Any ideas on what the problem may be?
Looks to be the issue is IE 10 doesn't support blob constructors like that... I changed the code and it exports now, but it doesn't seem to work with embedded fonts.
this.getBuffer(function (result) {
var blob;
try {
blob = new Blob([result], { type: 'application/pdf' });
}
catch (e) {
// Old browser, need to use blob builder
window.BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
if (window.BlobBuilder) {
var bb = new BlobBuilder();
bb.append(result);
blob = bb.getBlob("application/pdf");
}
}
if (blob) {
saveAs(blob, defaultFileName);
}
if (typeof cb === "function") {
cb();
}
});
Thanks for taking a look @brettjthom. I tested your code and can confirm the PDF is now generated, but that I get an error about embedded fonts when I open the doc (in Adobe Reader):
Cannot extract the embedded font 'AAAAAA+Roboto-Regular'. Some characters may not display or print correctly.
I don't have any experience with the internals of PDF documents. Do you have any hunches about what the problem might be?
I am actually not sure, I got the same thing. I still am totally confused why it isn't recognizing the constructor in IE10. Going look into it more today.
Thanks. It is weird. I debugged in IE10 and was able to successfully use new Blob() on the console with simple data sets. It only seems to fall over when passed the [result] array.
Let me know if you think I can help.
Yea, can't seem to figure this out.
Actually, I just got it, let me finish testing it and then I will do a pull request
Nice work @brettjthom! I've pulled down your changes and it works perfectly. Thanks for contributing.
Fixed by @brettjthom in pull request #297. Merged in commit df074b5adb1505fc89918a7963752c7dd791b0eb. Closing issue.
@brettjthom saved my day! Thanks for sharing your solution using the BlobBuilder!
@brettjthom , converting into byte array working fine for me in IE 10 #297 . Thanks for sharing
Most helpful comment
Looks to be the issue is IE 10 doesn't support blob constructors like that... I changed the code and it exports now, but it doesn't seem to work with embedded fonts.