asciidoctor-vscode icon indicating copy to clipboard operation
asciidoctor-vscode copied to clipboard

Can't render image in pdf with wkhtmltopdf 0.12.6

Open xiechao06 opened this issue 3 years ago • 3 comments

Description

with wkthmlttopdf 0.12.6, we must enable local file access to render images, this problem is discussed in https://stackoverflow.com/questions/62315246/wkhtmltopdf-0-12-6-warning-blocked-access-to-file.

May be this extension could add an option to supply arguments to wkthmltopdf?

xiechao06 avatar Jan 14 '22 10:01 xiechao06

That's a good idea, here's where we build the command line:

https://github.com/asciidoctor/asciidoctor-vscode/blob/ab1dc79924be9a0ee30326ebe11ed755f65f8f0f/src/commands/exportAsPDF.ts#L263-L270

ggrossetie avatar Jun 21 '22 19:06 ggrossetie

Though, I wonder if wkthmlttopdf will throw an error if we use this option on an older version? 🤔

ggrossetie avatar Jun 26 '22 14:06 ggrossetie

Even with --enable-local-file-access it won't work when using relative paths. Since we send the input content (HTML) as stdin, wkthmlttopdf will create a temporary file at file:///tmp/test.html and as a result relative paths won't work.

One way to solve this issue is to use data-uri to embed images in the HTML. Another way is to configure the imagesdir as an absolute path when exporting to PDF using wkthmlttopdf. A third way would be to create a temporary HTML file in the same base directory.

In https://github.com/asciidoctor/asciidoctor-vscode/pull/587 I've added --enable-local-file-access by default and also defined the Asciidoctor attribute data-uri.

ggrossetie avatar Jun 27 '22 11:06 ggrossetie