Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display PDF on PHP website without Flash/Adobe

I am not satisfied with the browsers internal behaviour of displaying PDFs. I would like to provide my users with an easy yet stylish PDF viewing experience on my sites. Something like Scribd, but managable and unter full security and control on my server.

I could provide inline links to GoogleDocsViewer or ZohoViewer. Or convert the PDF right after its upload with SWFTools and show the swf with native PHP or HTML5.

Anyway, somehow, after hours of reading and thinking, I am just not happy with any of the above approaches.

Any suggestions?

like image 253
maxpower9000 Avatar asked Sep 06 '11 11:09

maxpower9000


People also ask

How do I display a PDF on my website?

Generally, a hyperlink is used to link a PDF document to display in the browser. An HTML anchor link is the easiest way to display a PDF file. But if you want to display a PDF document on the web page, PDF file needs to be embedded in HTML. The HTML <embed> tag is the best option to embed PDF document on the web page.

How do I display the contents of a PDF in HTML?

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 I open a PDF in a div tag?

You can use the Javascript library PDF. JS to display a PDF inside a div. The size of the PDF can be adjusted according to the size of the div. You can also setup event handlers for moving to next / previous pages of the PDF.


2 Answers

Take a look at Google Docs Viewer. The following code will help you (untested):

<iframe src="http://docs.google.com/gview?embedded=true&url=PDF-URL" style="width:600px; height:500px;" frameborder="0"></iframe>

Update 13.09.2016: Google removed their generator. Even though, you can still use the viewer by appending the escaped document-url to the url above manually.

like image 122
andred Avatar answered Oct 01 '22 01:10

andred


I had to do something similar and finally I opted for generating images with ImageMagick, its works exactly the same way like Google Viewer.

But, if you want, you still can try to use PDF.js its from Mozilla and want to replace de browser PDF plugin.

like image 20
yvan Avatar answered Sep 30 '22 23:09

yvan