使用PHP进行PDF到JPG的转换 [英] PDF to JPG conversion using PHP

查看:200
本文介绍了使用PHP进行PDF到JPG的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP帮助将PDF转换为IMG(JPG)。

I'm trying to convert PDF to IMG (JPG) with help PHP.

我正在使用imagick扩展。

I'm using imagick extension.

这是我的代码

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

我的源pdf文件具有正确的尺寸(210x297 mm,与A4一样)。一切看起来都不错。
但我的jpg的页面尺寸为842x595像素,DPI为72。

my source pdf file has right dimension (210x297 mm, like A4 has). And everything looks good. But my jpg has page dimension as 842x595 px, and DPI is 72.

和img文件在纸张上小得多,然后是pdf,当我打印它时。

and img file much more smaller on paper then pdf, when i had print it.

从pdf制作图像文件的正确方法是什么,使其像pdf一样大(在纸上)

what is a proper way to make image file from pdf and make it so big as pdf (on paper)

推荐答案

ImageMagick使用GhostScript处理JPEG,因此你最好直接使用 exec GhostScript,效率会更高并给你更多的控制权。它也只是1 exec 语句,而不是使用IMagick函数。

ImageMagick uses GhostScript to process JPEGs, so you'd do better to exec GhostScript directly, which would be much more efficient and give you more control. It would also be only 1 exec statement, instead of playing around with the IMagick functions.

这篇关于使用PHP进行PDF到JPG的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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