最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Display wordpdf file on web page - Stack Overflow

programmeradmin3浏览0评论

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 = '/';
$r = $b.$a;  

<iframe src="=<?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 ://example/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

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./';
$r = $b.$a;  

<iframe src="http://docs.google./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./gview?url=http://example./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

Share Improve this question asked Dec 13, 2016 at 5:47 SamSam 1,3815 gold badges40 silver badges71 bronze badges 8
  • Earlier the file was getting displayed but all of a sudden it is not getting displayed now - what did you change between "earlier" and "now" – Jaromanda X Commented Dec 13, 2016 at 5:51
  • @Jaromanda X didn't changed anything, infact havn't worked on that entire webpage – Sam Commented Dec 13, 2016 at 5:53
  • Google may have stopped allowing embedding of doc viewing in iframes since it last worked. – flauntster Commented Dec 13, 2016 at 5:54
  • @flauntster if thats the case, can you please suggest some alternate way to fulfill the objective – Sam Commented Dec 13, 2016 at 5:55
  • pdf files are easy ... .docx not so easy – Jaromanda X Commented Dec 13, 2016 at 5:56
 |  Show 3 more ments

2 Answers 2

Reset to default 3

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./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.'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office./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/gcuzq343/

you can use
1. google docs viewer

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


2. Microsoft viewer

<iframe src='https://view.officeapps.live./op/embed.aspx?src=http://example./my-document.doc.doc' width='800px' height='600px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office./webapps'>Office Online</a>.</iframe>
发布评论

评论列表(0)

  1. 暂无评论