简体   繁体   English

在网页上显示 word/pdf 文件

[英]Display word/pdf file on web page

I have few files in doc/docx/pdf format stored on server's folder and their path are saved in database.我在服务器的文件夹中存储了 doc/docx/pdf 格式的几个文件,它们的路径保存在数据库中。 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 1) 文件格式正确且未损坏且确实存在于服务器文件夹中 2) 控制台没有给出任何错误 3) 尝试运行http://docs.google.com/gview?url=http://example .com/abc/request/file1.docx在浏览器上,也没有显示该文件,但是网络上给出的其他示例 url 正在工作

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如果有人能告诉任何其他方式(使用 jquery、javascript 或任何但可靠的方式)在网站上显示文件而不干扰原始文件的格式,我也将不胜感激

For PDF, you can use ViewerJS to render.对于 PDF,您可以使用ViewerJS进行渲染。

For doc/docx, consider using Microsoft Office Viewer as a walkaround if Google Docs Viewer is not stable enough to you对于 doc/docx,如果 Google Docs Viewer 对您来说不够稳定,请考虑使用 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'>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/ P/S:不知道为什么代码片段不起作用,但您可以在这里查看: https : //jsfiddle.net/gcuzq343/

you can use您可以使用
1. google docs viewer 1. 谷歌文档查看器

<iframe src="http://docs.google.com/gview?url=http://example.com/my-document.doc&embedded=true"></iframe>


2. Microsoft viewer 2.微软查看器

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://example.com/my-document.doc.doc' width='800px' height='600px' 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM