0

my question is how can I display a PDF or any office document (such as Office,Excel) document inside a web-page. I am using PHP MySQL to upload the documents to the database, and the documents also open. But, the problem is that the documents get downloaded sometimes instead of being viewed on the web page. This is something I don't want to happen and I want the files to be displayed on the user end even if the user does not have any extension in their browser that displays such files. So basically, what I want is to display the files that are uploaded on MySQL database using PHP. I am using XAMPP on localhost and I want my web application to work locally instead of running on a server. I was previously using and tags but they both download the files apparently, which I don't want to happen.

I have tried PDF.js from Mozilla but it displays PDF files only, whereas I want to display other documents such as word and excel files as well. Google Document Viewer can be a solution but I don't know how can I use it on a local server without facing complications such as a static IP and a domain name server.

  • Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output using the `[<>]` snippet editor. – mplungjan Jul 28 '20 at 06:44
  • For example https://stackoverflow.com/questions/20929920/display-docx-doc-on-browser-without-downloading-in-php – mplungjan Jul 28 '20 at 06:46
  • That is more like a Javascript problem than PHP or Mysql –  Jul 28 '20 at 06:48
  • Hello, I don't know, I just mentioned the tags which I found suitable. Furthermore, I have already researched a lot before actually posting this question, I've been looking for an answer since 2/3 days and about google docs viewer, maybe I failed to explain that I used it earlier already but it doesn't load the files when I'm using links such as localhost/myWebsite – Fahad Azeem Jul 28 '20 at 07:00

1 Answers1

1

You may try to convert the word document using PHP Office to PDF then convert PDF to image using ImageMagick

Edson Magombe
  • 313
  • 2
  • 14
  • Take a look here https://i.imgur.com/UqvlmPn.png It doesn't mention the extensions such as .doc, .docx or xls,xlsx – Fahad Azeem Jul 28 '20 at 07:09
  • It works for .doc and .docx $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('helloWorld.docx'); – Edson Magombe Jul 28 '20 at 09:47
  • Save as pdf $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF'); $objWriter->save('helloWorld.pdf'); – Edson Magombe Jul 28 '20 at 09:49