Laravel 8 Convert PDF to Image Example

July 26, 2021 | Category : Other

Hi,This post is focused on laravel 8 convert pdf to image example. This tutorial will give you simple example of laravel 8 convert pdf to image. This article goes in detailed on laravel 8 pdf to image convert. We will look at example of how to convert pdf to image in laravel 8.

Sometime we may need to convert pdf file to image in php laravel. If you need then i will give you simple example of how to convert pdf to image in laravel 6, laravel 7 and laravel 8 version.

we will use php imagick extension for convert pdf to image file. you must have to install imagick extension for pdf and give to permission. let's see step by step installation and configuration for imagick.

Step 1: Install imagick extension

in first step, we need install imagick extension for php, so let's install it and give permission as bellow:

Install php-imagick:

sudo apt install php-imagick

Check list of php-magick:

sudo apt list php-magick -a

Restart apache2 server:

sudo systemctl restart apache2

Check imagick installed:

php -r 'phpinfo();' | grep imagick




imagick module => enabled

imagick module version => 3.4.4

imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel

imagick.locale_fix => 0 => 0

imagick.progress_monitor => 0 => 0

imagick.skip_version_check => 1 => 1

Give Permission to Convert PDF File:

Open following file and update as bellow line into that line:

File Path: /etc/ImageMagick-6/policy.xml

Check imagick installed:

<policy domain="coder" rights="none" pattern="PDF" />


<policy domain="coder" rights="read|write" pattern="PDF" />

Step 2: Create Route

In this is step we need to create one route as bellow.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\DemoController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('convert-pdf-to-image', [DemoController::class, 'index']);

Step 3: Create Controller

in this step, we need to create DemoController and add following code on that file:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Imagick;

class DemoController extends Controller



* Write code on Method


* @return response()


public function index()


$imagick = new Imagick();


$saveImagePath = public_path('converted.jpg');

$imagick->writeImages($saveImagePath, true);

return response()->file($saveImagePath);



Now make sure you have to add "dummy.pdf" put on public folder. After run this url you will able to view image on your browser.

Now we are ready to run our example. so run bellow command so quick run:

php artisan serve

Now you can open bellow URL on your browser:



I hope it can help you...