8

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).

hakre
  • 184,866
  • 48
  • 414
  • 792
Dan
  • 3,209
  • 5
  • 33
  • 44
  • 1
    @BrianRoach Nope - already saw that question before posting. It only refers to PDFs. I'm looking for a tool that can do general documents (including PDFs but also XLS, DOC, and so on). – Dan Oct 10 '11 at 22:26
  • 1
    well for this, there is a trick combine both of this http://stackoverflow.com/questions/1225230/php-converting-excel-xls-to-pdfs and http://stackoverflow.com/questions/467793/how-do-i-convert-a-pdf-document-to-a-preview-image-in-php which is convert xls or whatever to pdf then get the image from pdf – aNi Oct 11 '11 at 07:39
  • I'm looking for this same thing and agree that this applies to more than just PDF/Office docs (eg LaTEX or SAS) – vol7ron Nov 30 '11 at 15:54

2 Answers2

9

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

http://www.mysql-apache-php.com/website_screenshot.htm

Mob
  • 10,739
  • 6
  • 39
  • 57
Dmitri Snytkine
  • 1,096
  • 1
  • 8
  • 14
0

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?

Community
  • 1
  • 1
ucefkh
  • 2,509
  • 2
  • 21
  • 18