How to convert image to pdf in laravel?

Member

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

How to convert image to pdf in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 10 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.

Related Threads:

How to convert blade file into pdf and image in laravel?
How to convert image url to base64 in laravel?
How to save iframe as pdf or image?
How to convert/save d3.js graph to pdf/jpeg?
How to cache an image and pdf in redis server?
How to update pdf file and image file in codeigniter?