How to embed a PDF in an HTML page?

writeToBhuwan picture writeToBhuwan · Dec 12, 2018 · Viewed 13.6k times · Source

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!

Answer

PPShein picture PPShein · Dec 12, 2018
<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