powershell 脚本中的 wkhtmltopdf 加载页面错误
wkhtmltopdf loading pages error in powershell script
我是 运行 来自 windows 机器上的 powershell 脚本的 wkhtmltopdf。
我使用的命令是
& "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" "C:\Desktop\Test.htm" "C:\Desktop\Report.pdf"
正在创建 pdf 文件,但它也会抛出错误
wkhtmltopdf.exe : Loading pages (1/6)
At line:1 char:2
+ & <<<< "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" "C:\Test.htm" "D:\Report.pdf"
+ CategoryInfo : NotSpecified: (Loading pages (1/6):String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
[> ] 0%[======> ] 10%[==============================> ]
50%[============================================================] 100%Counting pages (2/6)
[============================================================] Object 1 of 1Resolving links (4/6)
[============================================================] Object 1 of 1Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing[============================================================] Page 1 of 1Done
由于脚本返回错误,我无法继续进行。
请就此提出帮助。
您需要处理生成的错误文本。让我们将 std err 放入 std out 并捕获结果(如果您想查看它们)
$result = & 'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe' 'www.google.ca' "c:\temp\pdf.pdf" 2>&1
如果实际控制台输出不重要,您可以将其发送到 Out-Null
& 'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe' 'www.google.ca' "c:\temp\pdf.pdf" 2>&1 | Out-Null
上述接受的回答说捕获结果对我不起作用,但查看 WKHTMLTOPDF 文档我找到了抑制信息文本(默认输出)的正确方法。
您需要将 --log-level 设置为错误,这样它只会输出真正的错误文本,而不是 powershell 误解释为错误的信息文本。
--log-level <level> Set log level to: none, error, warn or
info (default info)
我是 运行 来自 windows 机器上的 powershell 脚本的 wkhtmltopdf。 我使用的命令是
& "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" "C:\Desktop\Test.htm" "C:\Desktop\Report.pdf"
正在创建 pdf 文件,但它也会抛出错误
wkhtmltopdf.exe : Loading pages (1/6)
At line:1 char:2
+ & <<<< "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" "C:\Test.htm" "D:\Report.pdf"
+ CategoryInfo : NotSpecified: (Loading pages (1/6):String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
[> ] 0%[======> ] 10%[==============================> ]
50%[============================================================] 100%Counting pages (2/6)
[============================================================] Object 1 of 1Resolving links (4/6)
[============================================================] Object 1 of 1Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing[============================================================] Page 1 of 1Done
由于脚本返回错误,我无法继续进行。 请就此提出帮助。
您需要处理生成的错误文本。让我们将 std err 放入 std out 并捕获结果(如果您想查看它们)
$result = & 'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe' 'www.google.ca' "c:\temp\pdf.pdf" 2>&1
如果实际控制台输出不重要,您可以将其发送到 Out-Null
& 'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe' 'www.google.ca' "c:\temp\pdf.pdf" 2>&1 | Out-Null
上述接受的回答说捕获结果对我不起作用,但查看 WKHTMLTOPDF 文档我找到了抑制信息文本(默认输出)的正确方法。
您需要将 --log-level 设置为错误,这样它只会输出真正的错误文本,而不是 powershell 误解释为错误的信息文本。
--log-level <level> Set log level to: none, error, warn or
info (default info)