Prevent to download pdf using embed tag

Viewed 2137

I'm using php, I'm creating a detailed view page of a profile, which has a pdf document, I use the embed tag to display it, but when opened it does not display the pdf file and Automatically download the file. Therefore the user can not see the pdf file displayed.

<embed src="/vh/assets/image/java.pdf" type="application/pdf" width="500" height="500"/>

Is there a way to solve this problem?

3 Answers

PDF documents are not supported as a src in the HTML <embed> tag.

You can get around this issue by using the Google Chrome PDF viewer as the embed `src.

<embed
  src="https://drive.google.com/viewerng/viewer?embedded=true&url=http://yourdomain.com/vh/assets/image/java.pdf"
  width="500"
  height="500"
/>

Note that your url in the src cannot be relative /vh/assets/image/java.pdf, it must be the full url http://yourdomain.com/vh/assets/image/java.pdf.


There also exist some third party libaries such as PDF.JS.

You can refer to w3schools embed tag,It is an html single tag,I can display pdf normally in chrome and firefox.Maybe you can check if your src is correct.

You can try below snippet #toolbar=0 helps disabling the options

<embed id="myObject1" src="file:///C:/Downloads/OoPdfFormExample.pdf#toolbar=0" type="application/pdf" width="1000px" height="600px">

This will disable download, print and other option of pdf viewer on browser enter image description here

Related