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?
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.
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.
Related
i need to display a pdf on the website. i've tried many ways but none of it worked for me.
let me explain what i've tried and why this is not ok for me.
i tried to insert pdf into html with <object> and <embed> tags. its ok if client browser has flash. but android phones don't have it so this is not a solution. plus iphone streching pdf so it is not readable.
then i tried to use just an <iframe> element. works fine only if browser has pdf plugin. in other cases browser starts file downloading. so this is not a solution too.
then i tried to use https://docs.google.com/gview?embedded=true&url=myfile.pdf. well and here i got troubles because there is some bug in in google docs because file displays only one in for times. the rest attempts ended with error code 200 from google. so as you already understood this is not a solution too.
then i tried to download php libs which should convert pdf to html (or image) but none of them worked beacuse i'm not that good at php and sometimes it asked to install third party libs so at this point i've failed too.
so now i'm stuck. i need to do something to display pdf on the page. i need some crossbrowser/responsive solution. it would be great if you help me to find some service like https://docs.google.com/gview which is gonna work without bugs or suggest any other solution. may be some small php lib with good documentation.
any help appriciated!
You can achieve by using PDF.js
https://github.com/mozilla/pdf.js/
for usage you can check this example http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples.
I have some pdf files and want to show them online in my website,not downloading or displaying with acrobat or firefox add-on, actullay I need a pdf viewer. I am not sure if there ia any prepared library or plugin. I guess I have to convert each page of pdf to an image file,but how can I do it?
thank you.
Like #Lix said most modern browsers have this built in it works well in chrome and firefox. This is what I do...
<object height="950" data="sample-report.pdf" type="application/pdf" width="860">
<p>It appears you don't have a PDF plugin for this browser.
No biggie... you can <a href="sample-report.pdf">click here to
download the PDF file.</a>
</p>
</object>
It degrades well if the browser doesn't support viewing PDF by letting one download it. I have looked for other solutions such as converting to html or image. But I don't like to load lots of large images and converting to html loses much of the formatting.
You can convert on your server though if your running linux with this command...
convert abc.pdf abc.jpg
-EDIT--
Firefox uses PDF.js to render PDFs. I've looked into before, but the complexity wasn't worth it for any of my projects.
Hope this helps. Aloha.
I think you are looking for this http://flexpaper.devaldi.com/
and the similar question
Flash Pdf viewer just like scribd
It is possible to view your files in google docs viewer in an iframe:
<iframe src="http://docs.google.com/gview?url=http://www.example.com/yourPDFfile.pdf" frameborder="0"></iframe>
Actually I have to upload pdf files and need to read on my website as book reader like a presentation. Please show me the possible ways to achieve my goals.
Thank you
I've been using flexpaper, I use pdf2swf to convert the pdf to swf as I used the flash version but there is a javascript version too.
One possible solution would be to use scribd. You simply upload your document to their website and embed their reader on your website. This is the easiest way, and you get things like searchability. Their reader also works like Adobe's Acrobat Reader.
The downside is that you are uploading your documents onto a public website, so everyone will be able to view it. Perhaps they might have settings where you can lock your documents so that only certain people can see them.
The next solution is to roll your own. You can use turn.js. In this case, you will need to find a way to convert your PDF files to HTML files or perhaps image files. With images, your text won't be selectable, and they won't be discoverable by search engines. Again, converting PDF to HTML can also be difficult as you might lose formatting in the process.
But it is entirely up to your use case. Personally, I would go with scribd, as their platform works very well, and you won't have to worry about implementing your own system.
I am currently working on a site that has to have the ability for users to view documents that are uploaded, however they need to be viewable in browser.
I know there is the Google docs viewer (however this does not seem to work when trying toopen it in a fancybox overlay), but are they any other alternatives, maybe some API's that could turn them into Flash or similar, and then I could simply embed it as a swf?
Any help would be greatly appreciated.
You said "however this does not seem to work when trying toopen it in a fancybox overlay" Did you tried with headers :
header("Content-type:application/pdf");
header("Content-type: application/vnd.ms-word");
For swf conversion see this
but are they any other alternatives, maybe some API's that could turn
them into Flash or similar, and then I could simply embed it as a swf?
Yes, there are APIs for converting word and PDF documents to Flash (swf). There is also a possibility to convert them to pure HTML so that the documents are shown directly in browser without Word or PDF software (Adobe Reader, etc.). Personally I use Print2Flash utility for putting my documents online. It converts my documents to both Flash and HTML formats at the same time. I do the conversion manually but there is an API for conversion as well as I can see here: http://print2flash.com/print2flashapi.php
We want to display a pdf-file on a webpage.
From what i can think of i see two possible solutions, displaying the file with some kind of pdf reader(maybe in flash?) or converting the pdf-file to html before displaying it.
How would you proceed to solve a problem like this?
Which would be the preferable method?
Well, there's always a third way: serve the PDF itself and leave the rest to the visitor.
For public websites, you can improve the user experience and reduce bandwidth overhead by embedding your PDF documents in your pages using one of the document sharing services such as:
http://www.scribd.com
http://www.docstoc.com
I should also add that scribd also has an API for uploading documents (and more).
If you absolutely need to display the PDF in the browser, you can use FlashPaper. It installs on Windows as a printer, and lets you convert any kind of document to SWF, which you embed in your HTML.
I've used it in several projects, but it's not an ideal solution. From the user standpoint, the best thing is to be able to download the PDF and read it with her favorite PDF viewer.
Try using the embed or object html tags.
http://blog.flashcolony.com/?p=244
Personally I wouldn't bother with that, and just rely on the user to have a proper pdf reader. If you go for a flash (or silverlight?) solution, you're imposing another requirement to the user to cover up the first one. On the other hand, converting PDF to HTML isn't all that easy, just look at how the output from Gmail's 'view as html' functionality looks.
As said, and as others already posted while I'm writing this I am sure, is to not bother and just let the visitor deal with having something to read pdf with ;-)
A solution not mentioned by others is to rasterize the PDF (say, via ghostscript) and serve the resulting image as PNG, JPG, etc. You have to choose the resolution (perhaps 72 dpi) and you have to understand that the document will become much less readable, especially to sensory impaired visitors.
Create a PHP file like this: I'm calling this first php file "firstfile.php"
<?php
header('Content-type: application/pdf');
$file='yourpdffile.pdf';
#readfile($file);
?>
Then create another PHP file and use iframe to get your desired PDF file. Sample code is below
<iframe src="http://localhost/Domainfolder/firstfile.php>" height="400px" width="750px">
</iframe>
This should do the trick unless you don't reference the links well. Enjoy ;)