Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload jpg/png, convert to pdf and save with PHP?

Been doing a fair bit of digging this morning, and not seeing an obvious answer - is it possible to save an image to pdf format using PHP (or one of it's many libraries)?

I am fairly familiar with GD, although it doesn't seem to have a built in PDF format exporter/save function from my reading so far.

If anyone has any suggestions, it would be much appreciated!!

like image 661
Jonathan Coe Avatar asked Aug 16 '11 16:08

Jonathan Coe


2 Answers

I tried to add this to the accepted answer. Here is an example of how to convert an image to a different format (including pdf) with the Imagick module:

$img = new Imagick('path/to/image.jpg');
$img->setImageFormat('pdf');
$success = $img->writeImage('path/to/image.pdf');

OR

$img = new Imagick();
$img->readImageBlob($imageBytes);
$img->setImageFormat('pdf');
$success = $img->writeImage('path/to/image.pdf');
like image 165
trey-jones Avatar answered Nov 17 '22 13:11

trey-jones


I see 2 other options :

  • the pdflib extension, but the opensource edition is quite limited (I don't know if you can use image functions without a paid license)
  • Zend_Pdf, which is a plain-PHP lib, part of the Zend Framework.
like image 1
Benjamin Dubois Avatar answered Nov 17 '22 11:11

Benjamin Dubois