12

Can someone tell me how to resolve following issues?

  1. wkhtmltopdf don't have option to pass proxy info (-p or --proxy) unlike in previous versions and its not using system $http_proxy and $https_proxy env variable too.

  2. wkhtmltopdf not working with HTTPS/SSL even though i set LD_LIBRARY_PATH for libssl.so and libcrypto.so

    [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
    

    and

    [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 working partially with HTTP. The output pdf files missing some content/background/positions.

    [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
    

Note: Im using wkhtmltopdf-0.12.1-1.fc20.x86_64 and qt-4.8.6-10.fc20.x86_64

kenorb
  • 155,785
  • 88
  • 678
  • 743
Murali Mopuru
  • 6,086
  • 5
  • 33
  • 51
  • These really sound like bugs that would be best answered by ashkulz in the github issue tracker, I think your best luck will be asking there. – Joel Peltonen Sep 22 '14 at 09:38
  • See: [Exit with code 1 due to network error: ContentNotFoundError #2051](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2051) – kenorb May 13 '15 at 16:49
  • I was receiving similar error and removed @font-face from css and problem disappeared. – pravin kumar sinha May 05 '18 at 03:38

4 Answers4

4

Unfortunately wkhtmltopdf doesn't handle downloading of complex websites, because it's uses Qt/QtWebKit library which seems to have some issues.

One problem is that wkhtmltopdf doesn't support relative addresses (GitHub: #1634, #1886, #2359, QTBUG-46240) such as:

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

and it loads them as local. One solution which I've found to this is the correcting html file in-place by ex in-place editor:

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

However it won't work for files which have these type of URLs on the remote.

Another problem is that it doesn't handle missing resources. You can try to specify --load-error-handling ignore, but in most cases it doesn't work (see #2051), so this is still outstanding. Workaround is to simply remove these invalid resources, before conversion.

Alternatively to wkhtmltopdf, you can use either htmldoc, PhantomJS with some additional script, for example using rasterize.js:

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

or dompdf (HTML to PDF converter for PHP, you can install by composer) with sample code below:

<?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");
kenorb
  • 155,785
  • 88
  • 678
  • 743
  • 1
    It went the same way you mentioned here, I too got to know relative resource paths, broken links etc after little more work on wkhtmltopdf. I fixed my problem with phantomjs scripts. – Murali Mopuru May 23 '15 at 13:22
1

my problem was solved removing @font-face from css.

Esther
  • 372
  • 5
  • 18
0

I had this problem before. and solve that like below.

wkhtmltopdf

In the above example i had some "src" files and "url"s that they refer to the static directory but the static directory didn't exist so wkhtmltopdf thrown me that error. for example:

src: url("file:///home/ehsan/Projects/Example/main/sib/static/WebYekan.eot");

and one more important thing i have to say is all the file paths in html files have to be an absolute path. do not use relative path at all.

I hope this help you.

Ehsan Ahmadi
  • 1,382
  • 15
  • 16
0

I searched a lot but could not find but finally found over here. I was using (./name) but that created the contentnotfound error.

But finally used the complete address and got the desired result

  • 1
    Sorry I don't quite follow what you are suggesting as an answer. Maybe a code example of your solution? – shox May 28 '20 at 20:24