Convert PDF to image in PHP without ImageMagick

15,924

Solution 1

"[...] requires PDF to image conversion, and we're obviously using imagemagick for it."

This is not obvious at all.

Because ImageMagick cannot convert PDF to images all by itself. It requires to use Ghostscript as its 'delegate'. So you may have installed ImageMagick, but not installed Ghostscript and it will not work.

Vice versa, you could have Ghostscript installed but not ImageMagick -- and you could still easily convert PDF to images. For instance, convert to JPEG with resolution 144 DPI (without specifying one, you'd get 72 DPI):

gs              \
  -o out.jpg    \
  -sDEVICE=jpeg \
  -r144         \
   in.pdf

Also, you are free to install Ghostscript wherever you want.

(BTW: I'd keep my hands off a hosting provider who does not offer a ImageMagick nor Ghostscript installation, let alone not allow to install it yourself...)

Solution 2

On linux systems statically linked things can work without external library dependencies. So if you could get/create a statically linked imagemagick executable, you could use it directly under docroot. Probably it isnt so trivial.

Or you could use remote sites for doing the conversion for you. Like: http://pdf2jpg.net/ (For posting to upload forms like this curl will be usefull.)

Share:
15,924
alexykot
Author by

alexykot

Updated on July 07, 2022

Comments

  • alexykot
    alexykot almost 2 years

    I have a PHP site that requires PDF to image conversion, and we're obviously using imagemagick for it. However, right now we're trying to move to different hosting, and it seems like I will not be able to install imagemagick package on the new hosting to do the same thing as we do now.

    So the question is - is there any way to convert PDF to image with either pure PHP means, or with anything else that can be just popped into DOCUMENT_ROOT and do not need to be properly installed into the system.

    This is a Linux system, but I have no idea what distribution, and I can't check as my rights in this system are really limited.

    thanks Alex.