0

I would like to embed an PDF preview in my web site. With the embed tag it works fine on modern browsers, but on older versions the following shows up:

enter image description here

Does someone know how to solve it without using any external JS library?

The data that I would like to preview is a base64 encoded pdf.

<embed src="data:application/pdf;base64,[:base64-encoded-pdf:]" width="100%" height="640px">
davidm
  • 1,570
  • 11
  • 24

2 Answers2

0

On older browsers, it may be an issue to use Data URIs, so try uploading your pdf to a website and embedding it into an iframe.

<iframe src='https://www.example.com/example.pdf' width="100%" height="640px">
Something went wrong :(
</iframe>
quicVO
  • 778
  • 4
  • 13
  • Then try turning the [data URI into a blob](https://stackoverflow.com/questions/12168909/blob-from-dataurl) – quicVO Mar 17 '21 at 19:03
0
<!-- initially load about:blank for MSIE -->
<iframe id="pdf" src="about:blank" height="100%" width="100%"></iframe>
var pdf_data_uri="data:application/pdf;base64," + PDF_DATA;
document.getElementById("pdf").setAttribute('src', pdf_data_uri);
caffeinatedbits
  • 471
  • 5
  • 8