how can we show pdf document in users browser.In the case the plugin is not installed. Is google api for pdf is usefull in this case?
-
Hmm, I don't think this is possible without some sort of client-side solution, but I'd like to know if anyone has any good ideas for alternate PDF display in the event there's no plugin, so +1 – Feb 13 '12 at 05:02
-
it always shows a download box.but i want to show the pdf file.in the case of pure html it opens the file. – StaticVariable Feb 13 '12 at 05:06
-
Here's a link to a similar post that might be of some use. http://stackoverflow.com/questions/956508/convert-pdf-to-html If the client side doesn't have a pdf viewer installed it won't be able to view pdfs. – CBusBus Feb 13 '12 at 05:06
-
@rdlowrey Thanks very much, I panicked a bit once it started lol. I hope you didn't take any offence in my comments, everyone forgets something from time to time and I'd hope to to receive the same opprobrium if the situation were reversed. – CBusBus Feb 13 '12 at 05:21
3 Answers
Google provides a tool to do this:
Option 1 - Generate your users a link:
https://docs.google.com/viewer?url=my_domain.com/my_pdf.pdf
Option 2 - Embed into page so that users stay on your site:
<iframe src="https://docs.google.com/viewer?url=my_domain.com/my_pdf.pdf&embedded=true">

- 11,757
- 4
- 41
- 57
There's a variety of (horribly ugly) ways you could go about that. You could convert the PDFs (either on the fly, or before and store them) to a format that's usable (plaintext) which is then sent to the browser (either as plain text, or marked up a touch).
There's a variety of command line tools to do the conversion, such as pdftotext
, along with some libraries. It's possible there's even PHP libraries with such functionality.
Though, you would need to use JavaScript on the client to detect the presence (well, lack there of!) of a PDF plugin, and then to load your converted document instead of a .pdf.

- 9,101
- 2
- 25
- 24
There is a good start of viewing PDF using HTML5. They try to render PDF using native HTML5 element, so no plugin required. But sure it requires modern browsers.
I haven't tried it yet, but maybe you can take a look to pdf.js. This is the working demo.

- 2,292
- 1
- 15
- 13