How to convert image to pdf in laravel?

Member

by addison , in category: PHP Frameworks , 3 months ago

How to convert image to pdf in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 3 months ago

@addison 

To convert an image to PDF in Laravel, you can use the "ImageToPdf" package which provides a convenient way to convert images to PDF format. Here is how you can install and use the package:

  1. First, install the ImageToPdf package using composer:
1
composer require spatie/image-to-pdf


  1. Next, you can use the following code to convert an image to PDF:
1
2
3
4
5
6
7
use SpatieImageImage;

$imagePath = 'path/to/image.jpg';
$pdfPath = 'path/to/output.pdf';

Image::load($imagePath)
    ->saveAsPdf($pdfPath);


Replace 'path/to/image.jpg' with the path to the image you want to convert and 'path/to/output.pdf' with the path where you want to save the converted PDF.


That's it! You have successfully converted an image to PDF in Laravel using the ImageToPdf package.