PHP 複数ページのPDFを一つの画像に

# How to combine a multi-page pdf file into a single long image: 

<?php 
$im1 = new Imagick();   
$im1->readImage('multi-page-pdf.pdf'); 
$im1->resetIterator(); 
# Combine multiple images into one, stacked vertically. 
$ima = $im1->appendImages(true); 
$ima->setImageFormat("png"); 
header("Content-Type: image/png"); 
echo $ima; 
?>

 

http://www.php.net/manual/en/imagick.appendimages.php

 

phpのマニュアルに上のが載っていたのに期待する結果にならなかった。。。

 

今回実現できた処理

 

$totalPage = 7; // PDFのページ数のカウントは次エントリ参照

 

$all = new Imagick();

 

for ($i = 0; $i < $totalPage; $i++) {

    $im = new Imagick("test.pdf[$i]");

    $im->thumbnailImage(640, 640, true);

    $im->setResolution(200,200);

    $im->setImageFormat("jpeg");

    $all->addImage($im);

    $im->destroy();

}

$all->resetIterator();

$combined = $all->appendImages(true);

$combined->writeImage("test_result.jpeg");

$combined->destroy();

$all->destroy(); 

 

 

その他参考になりそうなサイト

 

画像のリサイズ時参考になりそう

http://www.php.net/manual/en/function.imagecopyresampled.php#98560

http://stackoverflow.com/questions/17080214/imagick-pdf-to-jpg-missing-images

 

Imagick API

http://www.php.net/manual/ja/book.imagick.php

 

MAMPIMAGEMAGICKを使ってPDFからPNG生成

http://319ring.net/blog/archives/2210

 

http://serversideguy.com/2012/10/04/imagemagick-php-converting-a-pdf-to-image-and-displaying-without-saving/

 

http://319ring.net/blog/archives/2218

 

http://319ring.net/blog/archives/2210

 

http://ameblo.jp/linking/entry-10997312536.html

 

http://www.binarytides.com/convert-pdf-image-imagemagick-php/

 

http://codezine.jp/article/detail/4401

 

http://stackoverflow.com/questions/6087569/php-imagemagick-image-display

 

http://www.phpediary.com/convert-pdf-to-jpg-in-php

 

http://stackoverflow.com/questions/11004718/creating-array-populated-by-images-from-a-pdf-using-php-and-imagemagick