doulan9188 2010-04-07 14:28
浏览 48

将动态PDF管道输入Imagemagick并转换为PNG

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 :)

  • 写回答

1条回答 默认 最新

  • doutuo6689 2010-04-07 14:38
    关注

    Magick can open PDFs natively:

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?