PHP is a programming language commonly used on web servers. ImageMagick is a suite of tools that allows web servers to quickly and easily modify images when generating web content. Used together, ImageMagick and PHP are well suited to the task of taking Adobe Acrobat PDF files and converting them to ordinary images, such as GIFs, JPEGs, or PNGs.
- Skill level:
Open a text editor.
Paste the PHP tags into the text editor:
The rest of the code will go between these two tags.
Paste the following within the PHP tags:
$args = func_get_args();
$input = $args;
$output = $args;
exec("convert $input $output");
This provides the first and second arguments to the script from the command line, and assumes the first is the PDF file to be converted and the second is the file name that should be used for the new file.
Save your work as "pdf2img.php."
Tips and warnings
- For example, run the following to convert a PDF named "ws.pdf" to a JPG named "ws.jpg."
- php pdf2img.php ws.pdf ws.jpg
- A multipage PDF will generate an image for each page with a count, so the above command on a PDF with two pages will generate the following files:
- You can change the image format by changing the extension. ImageMagick will detect the extension and create the appropriate file. By changing "ws.jpg" to "ws.png" in the command line, you can use ImageMagick to create PNG files instead.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for