Home » Php » linux – Create a thumbnail preview of documents (PDF, DOC, XLS, etc.) in PHP (LAMP)

linux – Create a thumbnail preview of documents (PDF, DOC, XLS, etc.) in PHP (LAMP)

Posted by: admin July 12, 2020 Leave a comment


When users upload certain files to my site (such as .doc, .xls, .pdf, etc) I’d like to be able to generate a preview thumbnail (of the first page of the document). I’m working with PHP in a LAMP stack but would be happy with any library or command-line tool that can do the job (Linux highly preferred).

How to&Answers:

It’s not easy to convert certain document formats to image. php alone cannot do this.
The ‘proper’ way to do this is to first of all have the program installed on your server that can open the document in that format.
For example, for .doc documents you can use OpenOffice
it also can open most other document formats
You then need to setup your open office to work in ‘headless’ mode, sending the output to virtual display (XVFB is what you going to need on Linux)

You php script will then call OpenOffice, passing the path to uploaded doc. OpenOffice will actually open that doc. Then you need to create an image from the screen buffer. You can use ImageMagick for that

Then once you have the capture of your screen you can resize it to a thumbnail.

Look at this link for more details



The best way is to have all your documents converted to PDF
after that you can make preview thumbnail

& this is how simply explained
How do I convert a PDF document to a preview image in PHP?