如何使用Imagemagick PHP API将.pdf文件转换为.png [英] How to convert .pdf file to .png using Imagemagick PHP API

查看:152
本文介绍了如何使用Imagemagick PHP API将.pdf文件转换为.png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Imagemagick php API将.pdf文件转换为.png文件.

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

我们可以使用以下命令从shell进行操作:

we can do this from shell using this:

$convert sample.pdf sample_image.png

我们可以使用php exec()函数发出此命令,但是由于某种原因(安全性),我禁止使用php执行shell命令.

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

所以现在告诉我解决方案,如何不使用php exec()函数将我的.pdf文件转换为.png文件?

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.

推荐答案

您必须已安装php5-imagick

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

这篇关于如何使用Imagemagick PHP API将.pdf文件转换为.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆