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 and orWhere Condition Example


how to use where and orwhere condition in laravel 8, laravel 8 where and orwhere condition, where and orwhere laravel 8 example, orwhere and where in...

Crop Image Before Upload Using Croppie.js in Laravel 9


Using Laravel 9, crop an image before uploading it using Croppie.js. Before uploading an image, Laravel uses Ajax to crop it with croppie. Cropping an...

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

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

Helper Function Example in Laravel 8


helper function example in laravel 8, laravel 8 global helper function, how to use global helper function in laravel 8, add helper function in laravel