How to Convert PDF to JPEG Image using PHP

How to Convert PDF to JPEG Image using PHP

In this tutorial, you will learn how to convert PDF to JPEG using Imagick extension. It’s very easy to convert PDF to JPEG using Imagick extension. It also allows us to create, read, edit, and compose bitmap images easily.

PHP Imagick mostly built-in library with PHP installation so we do not need to include anything. If it is not installed then you can install it separately. I have shared the article link below for the same.

Step 1. Load imagick extension

$imagick = new Imagick();

Step 2. Load PDF file

$imagick->readImage('mytest.pdf');

 Step 3. Create Output Image

$imagick->writeImage('output.jpg');

Let’s Run all code together

<?php
$imagick = new Imagick();
$imagick->readImage('mytest.pdf');
$imagick->writeImage('output.jpg');
?>

Please visit, If you found any error like this “Class ‘Imagick’ not found”. It basically appears when your server does not have Imagick extension installed.

Check how to Install the ImageMagick PHP extension in Windows