2

I'm attempting to create a thumbnail of a multi-page PDF document using Gmagick, however I only want the first page of the PDF, not all of them.

$thumb = new Gmagick();
$thumb->readImage("/path/to/file/document.pdf");
$thumb->setImageFormat('JPG');
$thumb->thumbnailimage(198, 255);
$thumb->writeImage("/path/to/file/document.jpg");
$thumb->destroy();

This code works, however instead of creating just 1 image 'document.jpg' it creates 'document.jpg.0', 'document.jpg.1', 'document.jpg.2', etc. for all of the PDF pages. I could go and delete all the additional pages and rename the first image just 'document.jpg' but that seems a bit hacky to me.

Is there a way to designate just the first page of the PDF? I can't seem to find anything, and Gmagick's documentation seems to be lacking.

Jpsy
  • 20,077
  • 7
  • 118
  • 115
r0tterz
  • 198
  • 1
  • 2
  • 10
  • IIRC command-line imagemagick accepts `/path/to/file/document.pdf[0]`, maybe it works in GM as well – Pekka Aug 27 '13 at 16:49

1 Answers1

1

Pekka is right. GraphicsMagick - just like ImageMagick - accepts the special pdf file name notation filename.pdf[0] which would render only the first page, filename.pdf[1] for the second page, and so on.

Jpsy
  • 20,077
  • 7
  • 118
  • 115