2

I have this JS code:

link.href = 'data:application/pdf;base64,' + data;

where data is base64 string. The link opens properly in Firefox, but not in Chrome when size of PDF file is huge (> 1.5MB).

Why doesn't this work? Is there any workaround?

Michael M.
  • 10,486
  • 9
  • 18
  • 34

1 Answers1

0

Chrome doesn't allow opening data URLs for security reasons. You might be able to open the link using "Open in new tab" (right click menu).

As a work around, if possible, you can force the user to download the file using <a download="example.pdf" href= data:URL >

Or try using blob:URL instead of data:URL. This might help.

  • Thanks for the answer. This solution works in chrome when size of pdf file is less than 1.5 MB and this open in new tab option also does not work. I guess there is limitation in number of characters in URL in chrome which is preventing pdf from getting loaded. – user2311631 Jun 16 '22 at 11:24