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?

maxpower9000
  • 223
  • 2
  • 8

2 Answers2

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.

yvan
  • 938
  • 9
  • 18
  • Yes. Thanks! I forgot to mention PDF.js in my question. I read about it at [link](http://andreasgal.com/2011/06/15/pdf-js/). 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. – maxpower9000 Sep 06 '11 at 12:34
  • it work pretty much well, but like you said its still work in progress. You can see some working examples [here](http://andreasgal.github.com/pdf.js/) – yvan Sep 06 '11 at 12:39
  • 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 internally – Nir O. Jan 26 '12 at 19:28
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.

andred
  • 1,204
  • 1
  • 17
  • 29
  • 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. – maxpower9000 Sep 06 '11 at 12:45
  • 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' ); – maxpower9000 Sep 06 '11 at 12:49
  • This is by far the easiest method of forcing a PDF to open in a browser while safely embedding it. – Jared Eitnier Feb 21 '13 at 18:23