Question

I'm using imagemagick for getting the 1st page of pdf files as jpg image:

exec("convert pdffile.pdf[0] output.jpg");

Is it possible to get the 1st page of doc/docx file in the same way? When i tried to convert it I got the following error message:

"no decode delegate for this image format"

On research I found that imagemagick cannot read doc/docx files.

So what's the best method for extracting the first page of doc/docx files as jpg images in php ? If possible, I'd like to convert different file formats using the same code.

Was it helpful?

Solution

Unoconv is a shell command that utilizes LibreOffice/OpenOffice and supports all formats it can read as import and all formats it supports exporting to. It does export both to PDF and several image formats so if you are unable to get it to export the first page as image you can use it to create a PDF and use Imagemagick to do the rest.

It's in the repositories of the most common distros and since it's python it's probably possible to install it on a windows machine too with some efforts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top