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....

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

  • 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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.