Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf command fails

I am trying to convert a HTML file to PDF using wkhtmltopdf.

For that purpose I have installed wkhtmltopdf on a Debian box and am trying to run this command:

/usr/bin/xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf /path/convert.1303714349.4961.html.tmp /path/convert.1303714349.4961.pdf.tmp

I get the following error:

Loading page (1/2)
Error: Failed loading page file:///path/convert.1303714349.4961.html.tmp (sometimes it will work just to ignore this error with --ignore-load-errors)

The file does exist in /path/convert.1303714349.4961.html.tmp, and the permissions are set correctly. Can it have anything to do with the path being prepended with file://?

like image 617
phidah Avatar asked Apr 25 '11 07:04

phidah


People also ask

How do I run Wkhtmltopdf?

Open a command prompt window. The syntax for using the tool is fairly simple, enter the name wkhtmltopdf, followed by the URL of the web page, and the name of the PDF that you want to create, like so.

What is the use of Wkhtmltopdf?

Wkhtmltopdf is an open source simple and much effective command-line shell utility that enables user to convert any given HTML (Web Page) to PDF document or an image (jpg, png, etc).


2 Answers

I believe wkhtmtopdf does not handle local files with non-typical extensions. Try renaming the input file to *.html.

See issue and comments at https://web.archive.org/web/20131124022426/http://code.google.com/p/wkhtmltopdf/issues/detail?id=486.

like image 135
Daniel Andersson Avatar answered Sep 18 '22 12:09

Daniel Andersson


Another useful tip is to replace the spaces in the filename by some char like "_", because of when the filename has spaces the process fails loading page

like image 36
Wilson Avatar answered Sep 21 '22 12:09

Wilson