Creating images from PDF with ImageMagick Library
Every once in a while we need to export an image from a pdf file either for personal use or just to display an image to a website. Of course the most common use about we see in the web sites is to automatically export the FrontPage of a pdf. But how is this possible really?
In this tutorial we will use the latest version of ImageMagic library (currently 6.8) in order to perform a conversion from pdf to image. It is important to note that ImageMagic needs to be installed to the server machine both as a library and apache module in order to work.
To start with we have to first install some required libraries.
Also it would be good to install / uninstall first the imageMagick from a repo list in order to get the dependencies like ghostscript.
We can do that by issuing in the command line:
OR
After these steps we have to install the library itself.
After the install is done we can also run "make check" in order to make sure everything is ok. Please note that this command tests every file type so it may take a while.
In order to install the image magic module for apache we must execute:
Followed by an apache restart
In order to test the script with php we can create an index.php file and we also need a pdf file named demo.pdf. You can find that script attached.
Have fun converting your pdfs !
- index.php.txt (2019 Downloads)