使用PHP将JPG合并为一个PDF

问题描述:

我正在尝试使用一系列JPG并将它们组合成一个PDF文件,每个JPG都是它自己的页面。我猜想ImageMagick是最好的方法,但我似乎无法弄清楚如何组合文件。我在这里看到了combineImages方法:

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

但找不到任何例子。我是imagemagick的新手,所以我还在试图找出语法。

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

ImageMagick可以做我要问的吗?如果是这样,有人会写一个简单的例子吗?

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

谢谢!

PHP 中,您可以使用:

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

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

true 参数c> writeImages 很重要,因为它会使方法编写一系列图像,而不仅仅是一个。



您也可以从命令行执行此操作:

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