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

atob function failing in IE11 and pre-Chromium Edge #2901

Closed
LordGalahad opened this issue Sep 8, 2020 · 6 comments · Fixed by #2905
Closed

atob function failing in IE11 and pre-Chromium Edge #2901

LordGalahad opened this issue Sep 8, 2020 · 6 comments · Fixed by #2905

Comments

@LordGalahad
Copy link

It seems that I cannot load custom fonts in IE11 or pre-Chromium Edge.

My Project selects a font file and then converts it into a Base64 string

I have no problems running this into Chrome or FireFox.

But when it came to IE11 or old Edge, I get that PubSub error with an invalid calling object details.

I tried to debug and and ended up here

image

atob was returning an invalid calling object error (does not happen in Chrome or Firefox)

A workaround I did was instead of fetching the font into a Blob and using a FileReader to get the Base64 string of the font. I used arrayBuffer and just use this:

let fontData = new Uint8Array(content).reduce((data,byte)=>(data.push(String.fromCharCode(byte)),data),[]).join('');

It worked, and then I remembered I also had a lot of images in Base64 string that resulted in Corrupted PNG.

@HackbrettXXX
Copy link
Collaborator

If I understand your description correctly, you are not reporting a bug in jsPDF but describing how you created a valid Base64 string from a blob? If you think this is a bug in jsPDF please share a complete repro.

FYI, instead of creating a Base64 string, you can also pass a binary string.

@LordGalahad
Copy link
Author

Yeah my current workaround right now is passing a binary string instead. And yeah, it works this way. I guess we are too used to Base64 because we transport a lot of stuff to the server. But since everything is client side I think this is ok.

I may report this as an issue, but with IE11 being dropped next year and EDGE being placed by the Chromium Version, I will try to consult with my team about the priority of this one.

Weird though that when I called atob on my side I encounter no problems. But when I pass the Base64 string over to jspdf the problem occurs when the atob inside there is invoked.

@HackbrettXXX
Copy link
Collaborator

Ah I can imagine why it doesn't work in IE/Edge. We call atob without "this". The fix should be easy. I'm preparing a pull request.

HackbrettXXX added a commit to HackbrettXXX/jsPDF that referenced this issue Sep 8, 2020
@HackbrettXXX
Copy link
Collaborator

Could you check if the fix really resolves the issue (run npm run build first)?

@LordGalahad
Copy link
Author

Could you check if the fix really resolves the issue (run npm run build first)?

Thanks. It is working now 👍

@HackbrettXXX
Copy link
Collaborator

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants