在 embperl 中,我尝试使用 IPC::Open3 模块调用 wkhtmltopdf。
我从 wkhtmltopdf 获得输出(感谢ikegami),但没有输入到 wkhtmltopdf。
这与这个问题有关:perl / embperl — IPC::Open3
这是代码:
[-
use warnings;
use strict;
use IPC::Open3;
use POSIX;
use Symbol;
my $cmd = '/usr/local/bin/wkhtmltopdf - -';
my $pdf = '';
my $string = '<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World!!!
</body>
</html>';
my $fhOUT = gensym();
open($fhOUT, '>', '/dev/null') or die $!;
dup2(fileno($fhOUT), 1) or die $! if fileno($fhOUT) != 1;
local *STDOUT;
open(STDOUT, '>&=', 1) or die $!;
my $pid = open3(*HIS_IN, *HIS_OUT, *HIS_ERR, $cmd) or die "could not run cmd : $cmd : $!\n";
print HIS_IN $string;
close(HIS_IN);
while( <HIS_OUT> ) {
$pdf .= $_;
}
waitpid($pid, 0 ) or die "$!\n";
my $retval = $?;
# print "retval-> $retval<br />\n";
$http_headers_out{'Content-Type'} = "application/pdf";
$http_headers_out{'Content-Disposition'} = "attachment; filename=pdfTest.pdf";
$escmode = 0;
-]
[+ $pdf +]