简体   繁体   English

使用PHP将JPG合并为一个PDF

[英]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. 我正在尝试使用一系列JPG并将它们合并为一个PDF文件,每个JPG都是它自己的页面。 I'm guessing ImageMagick is the best way to do this, however I can't seem to figure out how to combine the files. 我猜ImageMagick是最好的方法,但我似乎无法弄清楚如何组合文件。 I see the combineImages method here : 我在这里看到combineImages方法:

http://php.net/manual/en/imagick.combineimages.php 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. 我是imagemagick的新手,所以我还是想弄清楚语法。

Can ImageMagick do what I'm asking? ImageMagick可以做我要问的事吗? And if so can someone write up a quick example? 如果是这样,有人会写一个简单的例子吗?

Thanks! 谢谢!

In PHP you can use: PHP您可以使用:

$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. writeImages上的true参数很重要,因为它会使方法编写一系列图像,而不仅仅是一个。


You also can do this from command line: 您也可以从命令行执行此操作:

 convert file1.jpg file2.jpg output.pdf 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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