Peeyush
Peeyush

Reputation: 4828

How to convert .pdf file to .png using Imagemagick PHP API

I want to convert .pdf file to .png file using Imagemagick php API.

we can do this from shell using this:

$convert sample.pdf sample_image.png

we can issue this command using php exec() function but due to some reason (security) I disabled the execution of shell commands using php.

so now tell me the solution that how can i convert my .pdf file to .png file without using the php exec() function?

There is another discussion about this here but it's not very clear.

Upvotes: 6

Views: 42053

Answers (2)

Luis Melgratti
Luis Melgratti

Reputation: 12060

you must have installed php5-imagick

$myurl = 'filename.pdf['.$pagenumber.']';
$image = new Imagick($myurl);
$image->setResolution( 300, 300 );
$image->setImageFormat( "png" );
$image->writeImage('newfilename.png');

Upvotes: 23

Pekka
Pekka

Reputation: 449753

but due to some reason(security) i disabled the execution of shell commands using php

You'll either need to re-enable the execution of shell commands, or install the ImageMagick PHP extension. See here on how to install it.

Upvotes: 1

Related Questions