Jonathan Coe
Jonathan Coe

Reputation: 1485

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

Upvotes: 9

Views: 20709

Answers (2)

trey-jones
trey-jones

Reputation: 3437

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');

Upvotes: 7

Benjamin Dubois
Benjamin Dubois

Reputation: 961

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.

Upvotes: 1

Related Questions