我正在使用 wkhtmltopdf 从 php 生成 pdf,但我有一个特殊的问题。当模板不使用任何外部资源时,一切都很好。但是当它通过 http/file 协议(protocol)导入任何东西时,我得到:
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。 我已经阅读了所有关于 SO 的 wkhtmltopdf 相关问题,但找不到答案。
PHP 5.5.5, Apache 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)
}
最佳答案
我遇到了类似的问题。它在我运行 Composer 更新后开始出现。
问题出在最新版本的 KnpLabs/snappy 存储库中。
恢复到此存储库的早期版本 (0.3.1) 为我解决了这个问题。
要更详细地了解导致问题的更改,请参阅:KnpLabs/snappy version changes
希望对您有所帮助。 :)
关于php - 从 php 执行时,Wkhtmltopdf 无法解析主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28347218/
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)