我使用php imagick来创建一个图像,而不是转换成pdf。使用php imagick。我编码了这个:
$image = new Imagick();
$height = 800; //height of the page;
$image->newImage(794, $height, "#f5f5f5");
$image->setImageFormat("jpg");
$card = new Imagick('card.jpg'); ; //get single card
$l_align = 190; //left alignment
for($i=0; $i < 4; $i++) //for creating multiple cards on a page
{
$image->compositeImage($card, Imagick::COMPOSITE_DEFAULT,10, ($l_align*$i)+10);
$image->compositeImage($card, Imagick::COMPOSITE_DEFAULT, 390, ($l_align*$i)+10);
}
$image->setResolution(72, 72);
$image->resetIterator();
$combined = $image->appendImages(true);
$image->setImageFormat("pdf");
$combined->writeImages( 'card.pdf', true );
header("Content-Type: application/pdf");
header('Content-Disposition: attachment; filename="card.pdf"');
echo file_get_contents('card.pdf');得到这样的东西

以pdf格式。现在,我想分页后,每6张卡打印成pdf。我用的是意象。请帮帮我。提前谢谢。
发布于 2014-05-19 13:32:52
您正在使用错误的函数将图像添加为新页。您应该使用addImage,它将新图像作为单独的页面添加,而不是将其附加到当前图像的底部。
这项工作的一个例子是:
$combined = null;
$images = [
'../../../images/Source1.jpg',
'../../../images/Source2.png',
];
foreach ($images as $image) {
if ($combined == null) {
$combined = new Imagick(realpath($image));
}
else {
$card = new Imagick(realpath($image)); ; //get single card
$combined->addImage($card);
}
}
$combined->setImageFormat("pdf");
$combined->writeImages( './card.pdf', true );顺便说一句,您的代码示例中有一些奇怪的内容--您甚至只是试图添加一个图像,而'resetIterator‘在那里做什么呢?
https://stackoverflow.com/questions/23737368
复制相似问题