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>
Related
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
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
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.
I am working on a job site where job seekers can upload their resume . When editing their profile , I want them to view their previous resume . I used <iframe> for this purpose , but instead of displaying the doc file,it shows an option to download . So how can I display their resume (in .doc,.docx and .odt format)
You can use php's fopen function, however there is a lot of unwanted code within a word doc file. Maybe a quick search could help you with what you want:
Reading/Writing a MS Word file in PHP
It would require a lot of effort. best bet is to create a wysiwyg editor instead of an upload that they can copy and paste to
You can't display .doc,.docx and .odt format files on browser. Basically a browser is designed for parsing HTML files only. You can use Flash to display doc inside your browser,
You need to embed the src, if you were to embed the source, it stops Adobe Reader or what not, taking over the browser entirely, and actually views it in the window, this should help:
Recommended way to embed PDF in HTML?
I know this is for PDF's but I would assume you can use it for .doc too.
We are downloading images to our computers when we open new webpages. For example: If a webpage has an image(image.jpg), our computer downloads it while we are surfing that page.
Some webpages are using ajax methods. For example: You don't see an image on the page's source codes, however your computer downloads an image. Because, if you click a link on that page, ajax will be showing that image...
Let me show an example:
<div id="ajax_will_load_image_here"></div>
Okay, how can php curl see (or download) that image? Curl can't see that image when I try to use preg_match function. Actually there is an image. I want to download that image by using php curl. Any advice?
If i understand the question correctly there is no convinient way of doing that.
Your crawler/spider would have to parse the website and evaluate javascript.
There are libraries for that but support is very limited.
There are however methods where an actual browser is used to evaulate the page (without displaying it but setting proper environment variables like resolution etc).
Then the generated source including javascript dom modifications is available.
This is for example how the google search previews are generated.
But if you require user interaction it gets pretty specific and complicated.
I am sorry to dissapoint you, but using curl and preg metch the old school way we used to when javascript was not yet so common wont work.
However for most legit use cases this is more than sufficient and websites are today more and more designed to be non-javascript compliant. Especially the content for crawling purposes. It is a must in search engine optimization, and which website doesnt want that?