Jump to content

PHP - convert pdf (1st page) to jpg using GhostScript


jaykappy

Recommended Posts

Have been reading up on using Ghost Script to convert a multi-page PDF file into a single jpg....I ONLY want the first page of the PDF to be converted to the jpg.

I was pretty confused while readying up on Ghost script and I was only getting bits and pieces of the examples...

Additionally there are 4-5 version of GhostScript....(GhostPCl, GhostPDF, GhostXPS, MuPDF)

 

wondering which one I should use OR is anyone recommends any others?

 

Has anyone done this before?  And care to show some examples.....Thanks....

I get pieces of code like this, but cant see where they are specifying the image name, output name and output location...

Can anyone help?

Thanks

 

$fp_pdf = fopen($pdf, 'rb');

$img = new imagick(); // [0] can be used to set page number
$img->readImageFile($fp_pdf);
$img->setImageFormat( "jpg" );
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality(90);

$img->setResolution(300,300);

$img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);

$data = $img->getImageBlob();

  • 1 month later...

If you want to convert pdf to jpg.i'd like to recomment this method to you:

 

// Method to open PDF document file in C# project
public static REDocument OpenDocumentFile(string filePath);
public static REDocument OpenDocumentFile(string filePath, BaseDecoder dec);

// Method to save PDF document to image file in C# project
public static void SaveImageFile(REImage image, string filePath);
public static void SaveImageFile(REImage image, string filePath, BaseEncoder enc);

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.