show pdf files in a php page - php

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>

Related

Display .docx (.doc) on Browser without downloading in php

Is there any alternative way of viewing a file(locally/online) in PHP? Since I want to display a .docx (.doc) file in my browser but it keeps on downloading it. So anyone who has a code for that? I keep on searching some other source code but no luck. I tried using Iframe but still keeps on downloading the file. Thanks!
An easy solution to display almost every type of document in browser using iframe.
Solution is Google Docs Viewer
Just use iframe as given below and replace url of document in it.
<iframe src='https://docs.google.com/viewer?url=ENTER URL OF YOUR DOCUMENT HERE&embedded=true' frameborder='0'></iframe>
By Replacing sample url for .docx file, above code becomes.
<iframe src='https://docs.google.com/viewer?url=http://calibre-ebook.com/downloads/demos/demo.docx&embedded=true' frameborder='0'></iframe>
By Replacing sample url for .pdf file, above code becomes.
<iframe src='https://docs.google.com/viewer?url=http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf&embedded=true' frameborder='0'></iframe>
Note: Document that you need to display in browser must have correct
url and must be publicly available, because Google needs to
fetch and display document, process fails if document is private and
you will see iframe with NO PREVIEW AVAILABLE
I have viewed some MS Office documents on www.dropbox.com . I just had a look, the tool used is called QuickLook Framework . It converts docx/doc to pdf and displays the pdf document on the website. But it is an iOS library.
If your documents are public, you could use Office web viewer or Google Docs viewer.
I have never used PHP to view Word documents online and have never seen a complete tool for that. But writing a parser is definitely possible, the question is - how much of the formatting do you want to retain?
If losing formatting is acceptable, you could try starting with answers from similar questions.
I don't know if this thread is closed or what but for google view
this code works prefectly
<iframe src='//docs.google.com/gview?url=URLOFDOC.docx&embedded=true' frameborder='0'></iframe>

Display PDF in <div> tag in my website

I'm developing a PHP MySql website in which pdf will be uploaded by site administrator. Viewers will get a list of all the pdf documents.
What I want is:
To open the PDF in my <div>.
No user should be able to download the PDF by any means.
I tried google doc viewer, it simply converts pdf to images which can be saved easily.
Also it gives View in Full option by which one can easily download the pdf.
And ofcourse,
<div><object data="test.pdf" type="application/pdf" width="300" height="200"></object></div>
is not working.
Please help..
You can use an iframe to embed a PDF inside a div, though it will rely on them having a PDF-reader plugin enabled on their browser. However, there is no way to show a PDF to a user in a way that does not let them save it
In order to read the PDF they HAVE to save a tmp version on their computer in any case, so you simply cannot prevent them from having a copy if they want.
There are a variety of ways to make it more difficult, but that's it. Tieson's solution, which draws the PDF to an HTML5 canvass makes it difficult to get the original PDF for non-technical users, but it only took about 2 minutes for me to find the PDF source and download the original (i.e. http://hazaar.funkynerd.com/pdfdoc/get?file=acr5smallpdf_80327_7.pdf). There are other, similar approaches using java or flash that don't actually show the PDF, but rather a rendering of the PDF by a third-party plugin, which will make it even more difficult, but even then the user could re-create the PDF using third-party tools or just simple screenshots, etc.
It's not really 100% reliable/stable, but there is a jQuery plugin for Mozilla's experimental PDF.js at http://dev.funkynerd.com/projects/jquery-pdfdoc

View word docs and PDF in browser?

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

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?
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.

displaying pdf on a website

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 ;)

Categories