首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为pdf2htmlex解析php中的stderr

为pdf2htmlex解析php中的stderr
EN

Stack Overflow用户
提问于 2014-05-16 20:54:10
回答 1查看 398关注 0票数 1

我有以下php代码:

代码语言:javascript
复制
<?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输出:

代码语言:javascript
复制
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 --Zoom1.3 --override-fstype 1 --hdpi 720 --dest-dir测试目录不起作用。它会转换文件并在目录中提供输出,但在网页上不会有任何回显。我怎么才能让它工作呢?

EN

回答 1

Stack Overflow用户

发布于 2015-04-26 09:18:04

pdf2htmlex不会将任何超文本标记语言输出打印到标准输出,只会打印到文件。

有两种方法可以做你想要的:

  • 首先写入临时文件,然后输出此文件。
  • 让pdf2htmlex写入一个先进先出(命名管道),这样你的pdf2htmlex脚本就可以在管道的另一端读取。

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

代码语言:javascript
复制
mkfifo htmlpipe.fifo
pdf2htmlEX foo.pdf htmlpipe.fifo

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

代码语言:javascript
复制
cat htmlpipe.fifo
<style type="text/css">...............
#sidebar {.......
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23695496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档