Wrong image paths when HTML input comes from stdin #4981
Comments
|
$ wkhtmltopdf --enable-local-file-access Hueber\ Lernmaterialen.md.html Hueber\ Lernmaterialen.md.html.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done This does NOT work: $ cat Hueber\ Lernmaterialen.md.html | wkhtmltopdf --enable-local-file-access - Hueber\ Lernmaterialen.md.html.pdf
Loading pages (1/6)
Warning: Failed to load file:///tmp/installation-error.png (ignore)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
|
I have the same error happening with 0.12.6 on Windows.
The working directory when the command is run is I notice that, when you read a file from the filesystem rather than stdin, paths are relative to the file and not the working directory (as expected). I wonder if wkhtmltopdf assumes that the system temp folder is the "real" location of the "file" read from stdin, and so assigns that as the base url. Personally, I would expect when reading from stdin that the current working directory would be considered the base url that images are referenced from. |
I'm trying to understand what you're describing here. Apparently you are piping in the input HTML file. Within that file, you have an image file -- is that specified with a relative address such as |
That is correct. The piped HTML is programmatically generated from a template, and the paths are relative to the template's folder rather than absolute. Relative paths are much easier to work with, especially as the development environment is Windows and the server environment is Linux; absolute paths would be totally different for each OS. When I call wkhtmltopdf, I am doing so with the template's folder as the current working directory. My expectation would be that this would allow wkhtmltopdf to understand relative paths as being relative to the current working directory. Having paths relative to the system temp folder doesn't make much sense to me. I ended up using weasyprint instead for the specific project I'm working on currently, as it's behavior in this regard was more in line with what I expected. However, I'm happy to provide any further details you'd like; I think there is a lot to like about wkhtmltopdf. |
It's starting to sound like wkHTMLtoPDF is either using a fixed "working directory" of |
Crossed that behavior too when trying to generate a template from a golang io.writer. ( so sending to wkhtml stdin ). When stdin is used as html input, wkhtml assumes Instead, it could assume the current folder is the running process's current folder or provide a switch to define the root for assets. This makes it difficult to secure local files when used it in a stream, and might unexpectedly disclose information from |
I'm facing the same issue, currently my only workaround is to store the input into a temporary file and pass it as a parameter to the process. |
This is to circumvent a bug in wkhtmltopdf See: wkhtmltopdf/wkhtmltopdf#4981
wkhtmltopdf version(s) affected: 0.12.6
OS information
Debian 10
Description
When HTML input comes from
stdin
the relative image path<img src="installation-error.png" alt="Sorry, an error has occurred" />
is wronglytransformed into
file:///tmp/installation-error.png
(see below).How to reproduce
installation-error.png
in the same directory.cat "input.html" | wkhtmltopdf --enable-local-file-access - tmp.pdf
Expected behavior
That the image is rendered and included in the resulting pdf.
Possible Workaround
none
The text was updated successfully, but these errors were encountered: