gpt4 book ai didi

qt - 使用wkhtmltopdf时如何处理ContentNotFoundError?

转载 作者:行者123 更新时间:2023-12-03 05:10:08 24 4
gpt4 key购买 nike

有人可以告诉我如何解决以下问题吗?

  1. 与以前的版本不同,wkhtmltopdf 没有传递代理信息(-p 或 --proxy)的选项,并且它也不使用系统 $http_proxy 和 $https_proxy 环境变量。

  2. 即使我为 libssl.so 和 libcrypto.so 设置了 LD_LIBRARY_PATH,wkhtmltopdf 仍无法使用 HTTPS/SSL

    [deploy@localhost ~]$ wkhtmltopdf https://www.google.co.in google.pdf
    loaded the Generic plugin
    Loading page (1/2)
    Error: Failed loading page https://www.google.co.in (sometimes it will work just to ignore this error with --load-error-handling ignore)
    Exit with code 1 due to network error: UnknownNetworkError

    [deploy@localhost ~]$ wkhtmltoimage https://www.google.co.in sample.jpg
    loaded the Generic plugin
    Loading page (1/2)
    Error: Failed loading page https://www.google.co.in (sometimes it will work just to ignore this error with --load-error-handling ignore)
    Exit with code 1 due to network error: UnknownNetworkError
  3. wkhtmltopdf 部分使用 HTTP。输出的 pdf 文件缺少一些内容/背景/位置。

    [deploy@localhost ~]$ wkhtmltopdf http://localhost:8880/ sample.pdf
    loaded the Generic plugin
    Loading page (1/2)
    Printing pages (2/2)
    Done
    Exit with code 1 due to network error: ContentNotFoundError

    [deploy@localhost ~]$ wkhtmltoimage http://localhost:8880/ sample.jpg
    loaded the Generic plugin
    Loading page (1/2)
    Rendering (2/2)
    Done
    Exit with code 1 due to network error: ContentNotFoundError

注意:我使用 wkhtmltopdf-0.12.1-1.fc20.x86_64 和 qt-4.8.6-10.fc20.x86_64

最佳答案

不幸的是wkhtmltopdf不能处理复杂网站的下载,因为它使用Qt/QtWebKit库,这似乎有一些问题。

一个问题是 wkhtmltopdf 不支持相对地址(GitHub: #1634#1886#2359QTBUG-46240 ),例如:

<img src="/images/filetypes/txt.png">
<script src="//cdn.optimizely.com/js/653710485.js">

并将它们加载为本地。我发现的一个解决方案是通过 ex 就地编辑器就地纠正 html 文件:

ex -V1 page.html <<-EOF
%s,'//,'http://,ge
%s,"//,"http://,ge
%s,'/,'http://www.example.com/,ge
%s,"/,"http://www.example.com/,ge
wq " Update changes and quit.
EOF

但是,它不适用于远程上具有此类 URL 的文件。

另一个问题是它不处理丢失的资源。您可以尝试指定 --load-error-handlingignore,但在大多数情况下它不起作用(请参阅 #2051 ),因此这仍然很突出。解决方法是在转换之前删除这些无效资源。

除了 wkhtmltopdf,您还可以使用 htmldocPhantomJS使用一些附加脚本,例如使用 rasterize.js :

phantomjs rasterize.js http://example.com/

dompdf (PHP 的 HTML 到 PDF 转换器,您可以通过 Composer 安装)示例代码如下:

<?php
// somewhere early in your project's loading, require the Composer autoloader
// see: http://getcomposer.org/doc/00-intro.md
$HOMEDIR = "/Users/foo";
require $HOMEDIR . '/.composer/vendor/autoload.php';

// disable DOMPDF's internal autoloader if you are using Composer
define('DOMPDF_ENABLE_AUTOLOAD', FALSE);
define('DOMPDF_ENABLE_REMOTE', TRUE);

// include DOMPDF's default configuration
require_once $HOMEDIR . '/.composer/vendor/dompdf/dompdf/dompdf_config.inc.php';

$htmlString = file_get_contents("https://example.com/foo.pdf");

$dompdf = new DOMPDF();
$dompdf->load_html($htmlString);
$dompdf->render();
$dompdf->stream("sample.pdf");

关于qt - 使用wkhtmltopdf时如何处理ContentNotFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25894251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com