DevelopingMagic / pdfassembler

MIT License
183 stars 34 forks source link

assemblePdf() fails in Microsoft Edge #10

Open Steve-OH opened 4 years ago

Steve-OH commented 4 years ago

The attached project uses PDFAssembler to open an existing minimal PDF and then immediately reassemble it and download it. This works fine in Chrome and Firefox, but fails in Edge with the console error message "0: Function expected."

To run: npm install followed by npm start; navigate to localhost:5002/dist and click the Test button. pdfAssemblerTest.zip

nvs2 commented 4 years ago

Hey @Steve-OH , I had this same problem. It was driving me crazy. I found the advice on this stackoverflow post to be the key. It turns out Edge doesn't support the File() declaration on line 577 of src/pdfassembler.ts. If you replace that line with:

resolve(new Blob([pdfData], { type: 'application/pdf' }));

It worked like a charm! I'd submit a PR if I had more time. I ended up importing the entire source of this project into my Angular 8 project as a service with the following additional, small correction. On line 132 I needed the typecast. It wasn't liking this return type without it:

fileReader.onload = () => resolve(<ArrayBuffer>fileReader.result);

I hope this helps!

Steve-OH commented 4 years ago

@nvs2 Thanks for the info. In our case, the use of PDFAssembler was always going to be an interim solution to do client-side patching of PDFs, until we finished moving all of our PDF generation to the client. The number of affected users is small (for now), so we had the luxury of telling people, "Don't use Edge."