Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a PDF in an HTML page?

I need to embed a PDF file in an HTML page for the users to see it on every major device. Most of the approaches work fine on desktop but they start to show problems on iPad devices. The PDFs are no longer scrollable if placed inside an iframe or embed tag.

I used the following techniques to overcome the problem:

1) Using pdf-image for node and converting the PDF to images and then sliding them in a div. The problem in this approach is that the image quality gets degraded and is not suitable for viewing on Web.

2) Using PDF.js by Mozilla It works fine on every device but it makes the page extremely slow and unresponsive on iPad

3) Using Google PDF viewer

<iframe src="https://docs.google.com/viewer?url=http://public-Url-of-pdf.pdf&embedded=true" frameborder="0" height="500px" width="100%"></iframe>

The problem with this approach is that I need to make my PDFs publicly available which I don't want to do for security reasons.

None of the above method is working for me. Is there any solution available to embed PDF in a page which works on iPad also.

One of my colleagues told me about using LibreOffice(open office) headless to embed PDFs in my page but I cannot find any documentation about it usage?

Can anyone please help? :(

Thanks in advance!

like image 906
writeToBhuwan Avatar asked Dec 12 '18 09:12

writeToBhuwan


People also ask

How do I embed a PDF in HTML website?

The easiest way to put PDF in an HTML document is using the <a> tag with its href attribute. You need to add the URL or the reference link of your PDF file to the element.

How do you embed a file in HTML?

Embedding an HTML file is simple. All we need to do is use the common „<link>“ element. Then we add the value „import“ to the „rel“ attribute. Using „href“ we attach the URL of the HTML file, just like we are used to when it comes to stylesheets and scripts.

Can I iframe a PDF?

The best way I found to display a PDF was to use an iframe. iframe stands for inline frame, and it allows you to embed another HTML document within the current one. You can read more about it here.


Video Answer


1 Answers

<embed src="http://example.com/the.pdf" width="500" height="375" />

Try above one for pure HTML. But another option is if you'd like to use with javascript, try Pdf.js by mozilla. https://github.com/mozilla/pdf.js

like image 63
PPShein Avatar answered Oct 16 '22 01:10

PPShein