How to display PDF on PHP website without Flash/Adobe
Asked Answered
R

2

7

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?

Ramey answered 6/9, 2011 at 11:28 Comment(0)
P
2

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.

Pierce answered 6/9, 2011 at 11:41 Comment(3)
Thanks! True! The GoogleDocsViewer does appear to be the best choice as of now. In the past I had some utf8-issues with it though. Many "PDFs" could not be displayed because somewhere in the filename or perhaps inside the PDF as well where unencoded utf-8 characters.Ramey
As of now I use a jQuery click-trigger to set the src-attribute of the iFrame to the PDF I want to display embedded in my site. Like so: $( 'A#trigger' ).click( function() { $( 'IFRAME' ).attr( 'src', 'linktothegoogledocsviewerpdf' );Ramey
This is by far the easiest method of forcing a PDF to open in a browser while safely embedding it.Sachet
K
2

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.

Kovar answered 6/9, 2011 at 11:39 Comment(3)
Yes. Thanks! I forgot to mention PDF.js in my question. I read about it at link. But it's a work in progress, isn't it? Is it anywhere usable yet? Will it be cross-OS and cross-browser? Well, maybe I should read up first.Ramey
it work pretty much well, but like you said its still work in progress. You can see some working examples hereKovar
unfortunately, generating images does not allow copy/paste. It looks that the best as of now is to take the output from poppler/pdftohtml/openoffice and add html5 font convertion, which is probably what scribd/crocodoc are doing internallyAdala
P
2

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.

Pierce answered 6/9, 2011 at 11:41 Comment(3)
Thanks! True! The GoogleDocsViewer does appear to be the best choice as of now. In the past I had some utf8-issues with it though. Many "PDFs" could not be displayed because somewhere in the filename or perhaps inside the PDF as well where unencoded utf-8 characters.Ramey
As of now I use a jQuery click-trigger to set the src-attribute of the iFrame to the PDF I want to display embedded in my site. Like so: $( 'A#trigger' ).click( function() { $( 'IFRAME' ).attr( 'src', 'linktothegoogledocsviewerpdf' );Ramey
This is by far the easiest method of forcing a PDF to open in a browser while safely embedding it.Sachet

© 2022 - 2024 — McMap. All rights reserved.