9

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!!

Jonathan Coe
  • 1,485
  • 4
  • 18
  • 36

2 Answers2

7

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');
trey-jones
  • 3,329
  • 1
  • 27
  • 35
  • How to add multiple images as single pdf?? – Mani Feb 11 '18 at 18:47
  • @Mani check out the documentation for [writeImages](http://php.net/manual/en/imagick.writeimages.php). There is a good example at the top of user contributed notes. – trey-jones Feb 13 '18 at 15:13
1

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.
Benjamin Dubois
  • 971
  • 7
  • 11