2015-02-05 73 views
1

我使用wkhtmltopdf从php生成pdf,但我有特殊的问题。当模板不使用任何外部源时,一切都很好。但是,当进口任何通过HTTP /文件协议,我得到:Wkhtmltopdf无法解析从php执行的主机

The exit status code '1' says something went wrong: 
stderr: "" 
stdout: "Loading pages (1/6) 
[> ] 0% 
[======> ] 10% 
[=======> ] 13% 
[============================================================] 100% 
Counting pages (2/6) 
[============================================================] Object 1 of 1 
Resolving links (4/6) 
[============================================================] Object 1 of 1 
Loading headers and footers (5/6) 
Printing pages (6/6) 
[> ] Preparing 
[============================================================] Page 1 of 1 
Done 
Exit with code 1 due to network error: HostNotFoundError 

异常却对我说: command: "D:\Programs\wkhtmlpdf\bin\wkhtmltopdf.exe" --lowquality "C:\Windows\TEMP\knp_snappy54d3831ed861e8.25642951.html" "C:\Windows\Temp\D60C.tmp".

在这种情况下,它是@import url(http://fonts.googleapis.com/css?family=Bree+Serif);导致了这一错误,但我根本无法使用任何链接,如果我想它从PHP工作。从命令行运行时,一切正常。我已经检查过,php是从“SYSTEM”用户执行它的,所以我产生了一个以SYSTEM身份运行的cmd窗口,并且创建了pdf没有任何问题。 Allow_url_fopen也被启用,openssl也是如此。

我正在使用KnpSnappyBundle,它使用Knp snappy库,它使用wkhtmltopdf。 我已阅读所有wkhtmltopdf相关的问题,但无法找到答案。

PHP 5.5.5,2.4.4阿帕奇

谢谢

更新:看来symfony的控制台组件做一些魔术proc_open。

$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);

而且参数的var_dump是

string(227) "cmd /V:ON /E:ON /C "("D:\Programs\wkhtmlpdf\bin\wkhtmltopdf.exe" --lowquality "C:\Windows\TEMP\knp_snappy54d3949bd6e035.20793656.html" "C:\Windows\Temp\2627.tmp") 1>"C:\Windows\Temp\sf_26C4.tmp" 2>"C:\Windows\Temp\sf_26C5.tmp""" 
array(3) { 
    [0]=> array(2) { 
     [0]=> string(4) "pipe" 
     [1]=> string(1) "r" 
    } 
    [1]=> array(3) { 
     [0]=> string(4) "file" 
     [1]=> string(3) "NUL" 
     [2]=> string(1) "w" 
    } 
    [2]=> array(3) { 
     [0]=> string(4) "file" 
     [1]=> string(3) "NUL" 
     [2]=> string(1) "w" 
    } 
} array(0) { 

} string(24) "D:\Web\e-diagnostyka\web" array(0) { 

} array(3) { 
    ["suppress_errors"]=> bool(true) 
    ["binary_pipes"]=> bool(true) 
    ["bypass_shell"]=> bool(true) 
} 

回答

4

我也有类似的问题。它在我运行作曲家更新后开始发生。

问题出在KnpLabs/snappy存储库的最新版本。

恢复到此存储库的早期版本(0.3.1)解决了我的问题。

对于那个正在导致问题所做的更改的更多详细信息,请参阅:KnpLabs/snappy version changes

希望它帮助。 :)