Combine JPG's into one PDF with PHP

谁说胖子不能爱 提交于 2019-12-03 13:44:50

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/25680490/combine-jpgs-into-one-pdf-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!