Export to PDF with wkhtmltopdf and subprocess

Hi everyone,

I would like to export some HTML page that are generated with a web microframework ( Flask )

I’m trying to use wkhtmltopdf and run

So in my Python\Flask code I’ve got this

HTMLrender = render_template('aTemplate.html')

run(['wkhtmltopdf', '-', '/somewhere/out.pdf'], timeout=10, input=HTMLrender, text=True)

The output seem missing all Html elements (I’ve got 3) that point somewhere else like
<img src="/home/aUser/Desktop/aPicture.jpg">

wkhtmltopdf give me this in the terminal →

Loading pages (1/6)
Warning: Blocked access to file
Warning: Blocked access to file
Warning: Blocked access to file
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol “about” is unknown
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol “about” is unknown
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol “about” is unknown
Counting pages (2/6)

And indeed I have only 3 element that references an “outside of html” files

in the aTemplate.html I have on purpose used full path to those references but I still got the same problems…

Any ideas ?

I wanted to ask directly on wkHTMLtoPDF GitHub but it’s closed since Januray 2023 :confused:

I’ve found a lead,

in wkHTMLtoPDF there is an argument
--enable-local-file-access
( Allowed conversion of a local file to read in other local files. )

I have to test it further but seem working…

I’ll close / set as resolved this thread when I solved it fully.

Meanwhile I’m all ears if you have better ways than wkHTMLtoPDF.

Cheers.

Indeed it was just this missing argument --enable-local-file-access that was generating the problem.

But now I’m shocked how my simple page converted as PDF trough that tool is totally not look like the original HTML :confused: