将动态 PDF 传输到 Imagemagick 并转换为 PNG

发布于 2024-08-28 17:11:20 字数 869 浏览 7 评论 0原文

我需要从动态(数据库驱动)pdf 创建缩略图。我过去使用过下面脚本的变体,但这现在似乎对我不起作用(页面只是挂起)。

<?php
 require_once('./template/all_includes.php');

 $descriptorspec = array(
  0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
  1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
  2 => array("pipe", "w")   // stderr is a file to write to
 );

 $cwd = '/tmp';
 $env = array('asdfadf' => '193');

 $convert = "convert pdf:- png:-";
 $process = proc_open($convert, $descriptorspec, $pipes, $cwd, $env);

    fwrite($pipes[0], 'php /var/www/html/domain.co.uk/store/pdf.php');
    fclose($pipes[0]);

    while(!feof($pipes[1])) $im .= fread($pipes[1], 1024);
    fclose($pipes[1]);

    $return_value = proc_close($process);

 header("Content-Type: image/png");
 echo $im;

   ?>

有人可以帮我解决这个问题吗?非常感谢:)

I need to create thumbnails from dynamic (database driven) pdf's. I've used a variation of the script below in the past, but this doesn't seem to be working for me now (page just hangs).

<?php
 require_once('./template/all_includes.php');

 $descriptorspec = array(
  0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
  1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
  2 => array("pipe", "w")   // stderr is a file to write to
 );

 $cwd = '/tmp';
 $env = array('asdfadf' => '193');

 $convert = "convert pdf:- png:-";
 $process = proc_open($convert, $descriptorspec, $pipes, $cwd, $env);

    fwrite($pipes[0], 'php /var/www/html/domain.co.uk/store/pdf.php');
    fclose($pipes[0]);

    while(!feof($pipes[1])) $im .= fread($pipes[1], 1024);
    fclose($pipes[1]);

    $return_value = proc_close($process);

 header("Content-Type: image/png");
 echo $im;

   ?>

Could anyone help me out with this please? Much appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2024-09-04 17:11:20

Magick 可以本地打开 PDF:

$im = new MagickWand('file.pdf[3]');  // open page 3 of the PDF
$png = $im->whateverTheMethodIsForPNG();

Magick can open PDFs natively:

$im = new MagickWand('file.pdf[3]');  // open page 3 of the PDF
$png = $im->whateverTheMethodIsForPNG();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文