如何使用 Imagemagick PHP api 将 .PDF 文件转换为 .PNG

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3833125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:15:40  来源:igfitidea点击:

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

phpimagemagickimagick

提问by Peeyush

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

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

we can do this from shell using this:

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

$convert sample.pdf sample_image.png

$convert sample.pdf sample_image.png

we can issue this command using php exec()function but due to some reason(security) i

我们可以使用 php exec()函数发出这个命令,但由于某种原因(安全)我

disabled the execution of shell commands using php.

禁用使用 php 执行 shell 命令。

so now tell me the solution that how can i convert my .pdf file to .png file without using

所以现在告诉我如何将我的 .pdf 文件转换为 .png 文件而不使用的解决方案

the php exec() function?

php exec() 函数?

there is another discussion about this herebut it's not very clear.

关于这个here还有另一个讨论,但不是很清楚。

-Thanks in advance
Peeyush Chandel

- 提前
致谢 Peeyush Chandel

回答by Luis Melgratti

you must have installed php5-imagick

你一定已经安装了 php5-imagick

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

回答by Pekka

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

但由于某种原因(安全),我禁用了使用 php 执行 shell 命令

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

您需要重新启用 shell 命令的执行,或者安装ImageMagick PHP 扩展。请参阅此处了解如何安装它。