简体   繁体   中英

Combine JPG's into one PDF with PHP

I'm trying to take a series of JPG's and combine them into one PDF file with each JPG being it's own page. I'm guessing ImageMagick is the best way to do this, however I can't seem to figure out how to combine the files. I see the combineImages method here :

http://php.net/manual/en/imagick.combineimages.php

But cannot find any examples. I'm new to imagemagick so I'm still trying to figure out the syntax.

Can ImageMagick do what I'm asking? And if so can someone write up a quick example?

Thanks!

In PHP you can use:

$images = array("file1.jpg", "file2.jpg");

$pdf = new Imagick($images);
$pdf->setImageFormat('pdf');
$pdf->writeImages('combined.pdf', true); 

The true parameter on writeImages is important because it will make the method write a sequence of images, not only one.


You also can do this from command line:

 convert file1.jpg file2.jpg output.pdf 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM