使用PHP将JPG合并为一个PDF [英] Combine JPG's into one PDF with PHP

查看:1577
本文介绍了使用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); 

<$ c $上的 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

这篇关于使用PHP将JPG合并为一个PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆