Example of Laravel 9 PDF to Image conversion. You will discover how to use the Laravel 9 app to convert PDF to Image in this tutorial.

You will first learn how to install the imagick package. Additionally, find out how to make the Imagick package available in Apache.

Install Laravel 9 App

To install the Laravel 9?app, first open your terminal OR command prompt and type the following line:

composer create-project --prefer-dist laravel/laravel blog

Installing Imagick PHP Extension And Configuration

The Imagick PHP extension is now installed using the following command in the terminal, which may be found in the Ubuntu repositories:

sudo apt install php-imagick

The apt list command can be used to check the list of versions that are available from the Ubuntu repository.

sudo apt list php-magick -a

Apt is instructed to list every version of a package that is available from the repositories via the -a flag. There is only one version accessible as of the time of this writing, and the output will resemble the following.

php-imagick/bionic,now 3.4.3~rc2-2ubuntu4 amd64 [installed]

restart apache web server

After that, restart Apache web server:

sudo systemctl restart apache2

Verify Installation

Run the next command to confirm the installation:

 php -m | grep imagick

The name of the module imagick will be the only line in the output of the command if the installation was successful.

imagick

Use the phpinfo() method for a much more thorough verification of whether the PHP module was correctly installed.

Run the following command on the command line.

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

This will produce the information displayed below, with the module's status indicated as enabled.

/etc/php/7.3/cli/conf.d/20-imagick.ini,
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.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.skip_version_check => 1 => 1

Alternatively, you can view a php script by adding the phpinfo() function to it and running it from a web browser. You can now see that the module has been installed and turned on.

Following certain authorisation changes, the path

/etc/ImageMagick-6/policy.xml

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

To Convert

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

Add Route

Add routes for the Laravel 8 app's PDF to Image Converter in this stage. Therefore, open "routes/web.php" and add the following route.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\MyController;

Route::get('pdf-to-image', [MyController::class, 'index'])->name('form');

Create Controller

Execute the following command to create MyController as the controller in this step:

php artisan make:controller MyController

To construct a controller named "MyController," use the following command in this step:

<?php

namespace App\Http\Controllers;

use Imagick;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;

class MyController extends Controller
{   
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $imagick = new Imagick();

        $imagick->readImage(public_path('dummy.pdf'));

        $imagick->writeImages('converted.jpg', true);

        dd("done");
    }
}

Open your terminal now, and then enter the command to launch the development server:

php artisan serve

You can now access the following URL in your browser:

http://localhost:8000/pdf-to-image

Recommended Posts

View All

Laravel where clause with date_format() example


laravel db raw where, laravel where date_format, laravel date_format mysql where, laravel date_format example, laravel where with month

Laravel 8 Generate PDF with Graph Tutorial


Laravel 8 generates a graphed pdf. You will understand how to generate a pdf with a graph in the Laravel 8 app in this tutorial

How To Use Chart JS In Laravel 


laravel chart js, laravel chartjs ajax example, how to create chart in laravel, how to use chart js in laravel, chartjs laravel example, laravel chart...

whereIn and whereNotIn Query Example in Laravel


In this model, we will see the Laravel whereIn and whereNotIn query model. Laravel whereIn and whereNotIn query example, laravel whereIn, laravel wher...

Laravel 9 Socialite Login with Facebook Tutorial


In this tutorial, we'll learn how to use the Socialite package in Laravel to login with a Facebook social networking account.