How to convert .PDF file to .PNG using Imagemagick PHP api

自闭症网瘾萝莉.ら 提交于 2020-06-25 04:18:48

问题


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.

-Thanks in advance
Peeyush Chandel


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/3833125/how-to-convert-pdf-file-to-png-using-imagemagick-php-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!