Jump to content

Convert PDF to JPG using Gmagick


JDTornado

Recommended Posts

Hi,

 

I have been pulling my hair out for the last week trying to figure this out and am just stuck. I have a set of PDF's (roughly 3,000) that I will need to convert to JPG's. I can do this using a batch through photoshop, but after it is done, I will need all new PDF's that are uploaded to be converted to a large JPG and a thumbnail JPG. Through my research it has appeared that the best way to do this is by using GraphicsMagick, with GhostScript. I am trying to get this to work with:

 

Windows 2008 rc2

IIS 7

PHP 5.3.3 Non-Thread Safe

GraphicsMagick-1.3.12-Q8

GhostScript 9.00

php_gmagick_nts.dll from http://valokuva.org/builds/

 

After I got everything installed on the server, it works fine through command line. I can convert a PDF to a jpg with no problems using something like:

gm convert test.pdf[0] test.jpg

However, when I use this PHP script:

 

<?php
//Instantiate a new Gmagick object
$image = new Gmagick('C:\inetpub\siteDir\test.pdf[0]');

//Make thumbnail from image loaded. 0 for either axes preserves aspect ratio
$image->thumbnailImage(100, 0);

header( "Content-Type: image/jpeg" );
echo $image;
?>

 

I get the following error:

 

thrown in C:\inetpub\siteDir\drawings.php on line 13

#1 {main}

#0 C:\inetpub\siteDir\drawings.php(13): Gmagick->__construct('C:\inetpub\sit....')

Stack trace:

[17-Oct-2010 18:40:46] PHP Fatal error: Uncaught exception 'GmagickException' with message 'Postscript delegate failed (C:\inetpub\siteDir\test.pdf)' in C:\inetpub\siteDir\drawings.php:13

 

I have tried doing this as well:

 

<?php
exec('gm convert C:\\inetpub\\siteDir\\test.pdf[0] C:\\inetpub\\siteDir\\test.jpg');
?>

 

 

If I do that in the command line on the server, it works without any problems. When I do that in the PHP script, I get no errors, but the conversion doesn't happen either. Does anyone have any ideas? Is there a better method for doing this? Am I just missing something? Any help would be greatly appreciated. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/216128-convert-pdf-to-jpg-using-gmagick/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.