How to embed pdf file in html?

Viewed 10135

I want to embed pdf files in my html ( either using the embed tag or the iframe tag ).

I've tried the following two. All work well on firefox but not on chrome, chromium and android browsers.

<embed type="application/pdf" src="myfile.pdf"></embed>
<iframe class="embed-responsive-item" src="myfile.pdf" allowfullscreen></iframe>

I've also tried reading the pdf file with php and then using an iframe to display it like this

header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$_GET['pdf']);
@readfile($CONFIG['PDF']."/".$_GET['pdf']);

Again, this doesn't work on chrome / chromium and mobile browsers. It only works on desktop firefox.

I'm not sure if this is important information but I've also Set the X-Frame-Options "ALLOW-FROM mydomain.com"

Here you will find an example of what the issue is.

Is there any other way that I can embed a pdf file on a web page?

1 Answers

The Chrome browser on Android no longer supports PDF embeds. You can get this by using the Google Drive PDF viewer:

<embed src="https://drive.google.com/viewerng/
viewer?embedded=true&url=http://example.com/the.pdf" width="500" height="375">

You can also use Google PDF viewer for this purpose. You need to upload your PDF somewhere before and just use its URL:

<iframe src="http://docs.google.com/gview? url=http://example.com/mypdf.pdf&embedded=true" style="width:718px; height:700px;" frameborder="0"></iframe>
Related