[ACCEPTED]-Creating two pdf pages with Imagick-imagick
I know this is long past due, but this result 3 came up when I was trying to do the same 2 thing. Here is how you create a multi-page 1 PDF file in PHP and Imagick.
$images = array(
'page_1.png',
'page_2.png'
);
$pdf = new Imagick($images);
$pdf->setImageFormat('pdf');
if (!$pdf->writeImages('combined.pdf', true)) {
die('Could not write!');
}
Accepted answer wasn't working for me, as 4 a result, it always generated one page pdf 3 (last image from constructor), to make this 2 work I had to get file descriptor first, like 1 this:
$images = array(
'img1.png', 'img2.png'
);
$fp = fopen('combined.pdf', 'w');
$pdf = new Imagick($images);
$pdf->resetiterator();
$pdf->setimageformat('pdf');
$pdf->writeimagesfile($fp);
fclose($fp);
Is this working?
$im->setImageFormat("pdf");
$im->writeImage("file1.pdf");
$im2->setImageFormat("pdf");
$im2->writeImage("file2.pdf");
exec("convert file*.pdf all.pdf");
0
CAM::PDF is a pure-Perl solution for low-level PDF 10 manipulation like this. You can either 9 use the appendpdf.pl command-line tool, or do it programmatically 8 like this:
use CAM::PDF; my $doc1 = CAM::PDF->new('file1.pdf'); my 7 $doc2 = CAM::PDF->new('file2.pdf'); $doc1->appendPDF($doc2); $doc1->cleanoutput('out.pdf');
If 6 you can figure out how to make ImageMagick 5 write to a string instead of to a file (I'm 4 not an ImageMagick expert...) then you save 3 some performance overhead by keeping it 2 all in Perl.
(I'm the author of CAM::PDF. It's 1 free software: GPL+Artistic dual-licensed).
I do not know php or this Imagick library, but 8 if calling an external program is acceptable 7 I can recommend the program pdfjoin to merge pdf 6 files.
It does have an dependency to pdflatex, so 5 if this is something you intend to run on 4 a server you might have to install extra 3 latex stuff, but the end result from pdfjoin 2 is very good, so I think it will be worth 1 it.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.