简体   繁体   English

Python Flask WkHTMLtoPDF 未加载本地 CSS 和文件

[英]Python Flask WkHTMLtoPDF not loading local CSS and files

I am getting the following error, despite adding the appropriate options尽管添加了适当的选项,但我收到以下错误

rendered= render_template('data.html', data=data)
options = {'enable-local-file-access' : True}
pdf = pdfkit.from_string(rendered,False,configuration=config,options=options)

From what I read I need to give the file access, hence I defined that options to allow local file access.根据我阅读的内容,我需要授予文件访问权限,因此我定义了该选项以允许本地文件访问。 But it still throws a bunch of weird errors但它仍然会抛出一堆奇怪的错误

OSError: wkhtmltopdf reported an error:
Loading pages (1/6)
Error: Failed to load file:///static/css/bootstrap.min.css, with network status code 203 and http status code 0 - Error opening /static/css/bootstrap.min.css: The system cannot find the path specified.
Warning: Failed to load file:///static/css/all.css (ignore)
Warning: Failed to load file:///static/css/base.css (ignore)
Error: Failed to load file:///static/js/jquery-3.2.1.slim.min.js, with network status code 203 and http status code 0 - Error opening /static/js/jquery-3.2.1.slim.min.js: The system cannot find the path specified.
Warning: Failed to load file:///static/js/sweetalert2@11.js (ignore)
Warning: Failed to load file:///static/css/modern.css (ignore)
Error: Failed to load file:///static/js/survey.jquery.min.js, with network status code 203 and http status code 0 - Error opening /static/js/survey.jquery.min.js: The system cannot find the path specified.
Error: Failed to load file:///static/js/jquery-3.6.0.min.js, with network status code 203 and http status code 0 - Error opening /static/js/jquery-3.6.0.min.js: The system cannot find the path specified.
Error: Failed to load file:///static/js/popper.min.js, with network status code 203 and http status code 0 - Error opening /static/js/popper.min.js: The system cannot find the path specified.
Error: Failed to load file:///static/js/bootstrap.min.js, with network status code 203 and http status code 0 - Error opening /static/js/bootstrap.min.js: The system cannot find the path specified.
Warning: Failed to load file:///static/img/logo.png (ignore)
Error: Failed to load http://true/, with network status code 3 and http status code 0 - Host true not found
Error: Failed loading page http://true (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -

ContentNotFoundError seems to occur when another file that is loaded in the file in error cannot be found.当无法找到错误文件中加载的另一个文件时,似乎会发生 ContentNotFoundError。 An example of this is loading font files.这方面的一个例子是加载字体文件。

Bootstrap contains a lot of fonts and they cause errors. Bootstrap 包含很多 fonts 并且它们会导致错误。

I also don't know how to get all fonts to load correctly.我也不知道如何让所有 fonts 正确加载。

If you simply read the font with CSS, there is a way to convert it to base64如果只是用 CSS 读取字体,有一种方法可以将其转换为base64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM