PDF到JPG Imagic页面选择 [英] PDF to JPG Imagic page selection

查看:288
本文介绍了PDF到JPG Imagic页面选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何为命令行执行此操作的大量答案

Loads of answers on how to do it for a command line

convert /path/to/file/file.pdf[3] output.jpg

很棒......但如果我在内存处理中使用,我会怎么样?我正在使用PDFlib生成PDF,然后将其缓冲区输出到我想要生成所选页面的jpg预览的函数。怎么样?我的代码:

great... but what if I am using in memory processing, I am generating PDF with PDFlib and then output its buffer to a function that I want to generate jpg preview of selected page. How? My code :

    [...]
    $buf = $pdf->get_buffer();

    //$buff is just a PDF stored in a string now.

    $im = new Imagick();
    $im->readimageblob($buf);

    $im->setImageFormat("jpg");
    $im->setimagecompressionquality(60);

    $len = strlen($im);
    header("Content-type: image/jpeg");
    header("Content-Length: $len");      
    header("Content-Disposition: inline; filename=test.jpg");

    echo $im;

这会创建一个jpeg,但始终返回PDF的最后一页。我希望能够选择哪一个将被转换。如果不保存临时文件并使用命令行(exec('convert /path/to/file/file.pdf[3] output.jpg'))语法,它是否可行?

This creates a jpeg but always returns last page of the PDF. I want to be able to choose which one will be converted. Is it doable without saving temporary files and using command line (exec('convert /path/to/file/file.pdf[3] output.jpg')) syntax?

让我补充说我试过了

    $im->readimageblob($buf[2]);

并且不起作用:)

推荐答案

不幸的是,这不是好消息,但我可以明确地说,截至撰写本文时,ImageMagick(和PHP库)不支持您尝试的页面符号使用。 (对于未来发现这一点的人:我正在检查php-imagick-3.0.1和imagemagick-6.6.0.4)。

It's not good news unfortunately, but I can definitively say that, as of time of writing, the ImageMagick (and PHP libraries) don't support the page notation that you're trying to use. (For people from the future finding this: I'm checking php-imagick-3.0.1 and imagemagick-6.6.0.4).

我正在尝试与你完全相同的东西,我刚刚花了最后几个小时在源头上拖网,试图找出它的作用以及它是如何获取页面的,看起来它只是在阅读时不会使用它stream(即readBlob()调用)。

I'm trying to do the exact same thing as you, and I've just spent the last few hours trawling through the source, trying to figure out what it does and how it gets the pages, and it looks like it simply won't use it when reading from a stream (ie. the readBlob() call).

因此,我只是将它放在一个临时文件中,然后从那里读取它。不那么优雅,但它会起作用。

As such, I'm just going to be putting it in a temporary file and reading it from there instead. Not as elegant, but it'll work.

这篇关于PDF到JPG Imagic页面选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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