在网页上显示word / pdf文件 [英] Display word/pdf file on web page

查看:219
本文介绍了在网页上显示word / pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在doc / docx / pdf格式的文件存储在服务器的文件夹中,并且它们的路径保存在数据库中。我希望从数据库中获取这些文件的路径,然后将其显示在我的网站上。



在数据库中,文件以这种格式存储

  id路径
1 abc / request / file1.docx
2 abc / request / file2.pdf
3 abc /request/file3.docx

要显示我使用以下方法的文件

  $ a = $ data->路径; 
$ b ='http://example.com/';
$ r = $ b。$ a;

< iframe src =http://docs.google.com/gview?url=<?php echo $ r;?>& embedded = truestyle =width: 100%;身高:600px; FRAMEBORDER = 0 >< / iframe中>



问题


<


我做了以下检查以查看这些文件是否正在显示文件的有效性

lockquote
1)文件格式正确,没有损坏,并存在于服务器文件夹
上2)控制台没有给出任何错误
3)试图运行 http://docs.google.com/gview?url=http://example.com/abc/request/file1.docx 在浏览器上,那里也没有显示文件,但在网上给出的其他示例url正在工作


任何人都可以请告诉如何纠正错误。我也很感激,如果任何人可以告诉任何其他方式(使用jQuery,JavaScript或任何但可靠的方式)在网站上显示的文件,而不会影响原始文件格式

解决方案

对于PDF,您可以使用 ViewerJS 进行渲染。



对于doc / docx,如果Google文档查看器对您来说不够稳定,请考虑使用Microsoft Office Viewer作为解决方案。

 < iframe src ='https://view.officeapps.live.com/op/embed.aspx?src = http%3A%2F %2Fieee802%2Eorg%3A80%2Fsecmail%2FdocIZSEwEqHFr%2Edoc'width ='100%'height ='900px'frameborder ='0'>这是一个嵌入< a target ='_ blank'href ='http:// office.com'> Microsoft Office< / a>文档,由< a target ='_ blank'href ='http://office.com/webapps'> Office Online< / a>提供支持。< / iframe>  

P / S:不知道代码片断的原因不工作,但你可以看看这里: https://jsfiddle.net/gcuzq343/ p>

I have few files in doc/docx/pdf format stored on server's folder and their path are saved in database. I wish to fetch the path of these files from database and then display it on my website.

In the database the files are stored in this format

id    path
1    abc/request/file1.docx
2    abc/request/file2.pdf
3    abc/request/file3.docx

To display the file i used the following method

$a = $data->path;
$b = 'http://example.com/';
$r = $b.$a;  

<iframe src="http://docs.google.com/gview?url=<?php echo $r; ?>&embedded=true" style="width: 100%; height: 600px;" frameborder="0"></iframe>

Issue

Earlier the file was getting displayed but all of a sudden it is not getting displayed now

I did the following checks to see the validity of file

1) File is in proper format and is not corrupted and does exist on server folder 2) The console is not giving any errors 3) Tried to run http://docs.google.com/gview?url=http://example.com/abc/request/file1.docx on browser, there also the file is not getting displayed, however the other example url given on net are working

Can anyone please tell how to correct the error. And I would also appreciate if anyone could tell any other way(using jquery, javascript or any but reliable way) to display the files on website without disturbing the formatting of the original file

解决方案

For PDF, you can use ViewerJS to render.

For doc/docx, consider using Microsoft Office Viewer as a walkaround if Google Docs Viewer is not stable enough to you

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http%3A%2F%2Fieee802%2Eorg%3A80%2Fsecmail%2FdocIZSEwEqHFr%2Edoc' width='100%' height='900px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>
  

P/S: Don't know why the code snippet is not working, but you can take a look here: https://jsfiddle.net/gcuzq343/

这篇关于在网页上显示word / pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆