1

我有以下 php 代码:

<?php
header('Content-Type: text/HTML; charset=utf-8');
header( 'Content-Encoding: none; ' );

//$cmd = "pdf2htmlEX --zoom 1.3 --override-fstype 1 --hdpi 720 --dest-dir test test/test_data/Harsh_Singh_191_Marketing_IM18.pdf";
$cmd = "ping 127.0.0.1";
$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 pipe that the child will write to
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes);
echo "<pre>";
if (is_resource($process)) {
   while ($s = fgets($pipes[1])) {
       print $s;
       flush();
   }
}
echo "</pre>";

?>

当 $cmd 设置为“ping 127.0.0.1”时,此代码可以正常工作,并实时提供 php 输出:

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

但是 pdf2htmlEX 命令,即 $cmd = "pdf2htmlEX --zoom 1.3 --override-fstype 1 --hdpi 720 --dest-dir test test/test_data/Harsh_Singh_191_Marketing_IM18.pdf" 不起作用。它确实转换文件并在目录中提供输出,但网页上没有任何内容。我怎样才能让它工作?

4

1 回答 1

0

pdf2htmlex 不会将任何 HTML 输出打印到标准输出,仅打印到文件。

有两种方法可以满足您的需求:

  • 先写入一个临时文件,然后输出这个文件。
  • 让 pdf2htmlex 写入 FIFO(命名管道),以便您的 PHP 脚本可以在管道的另一侧读取。

我在 Linux 命令行上使用 FIFO 对其进行了测试,它也应该以类似的方式与您的 PHP 脚本一起工作:

mkfifo htmlpipe.fifo
pdf2htmlEX foo.pdf htmlpipe.fifo

这将阻塞,直到您从管道中读取。在另一个终端:

cat htmlpipe.fifo
<style type="text/css">...............
#sidebar {.......
于 2015-04-26T01:18:04.167 回答