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



尽管添加了适当的选项

,我还是得到了以下错误
rendered= render_template('data.html', data=data)
options = {'enable-local-file-access' : True}
pdf = pdfkit.from_string(rendered,False,configuration=config,options=options)

从我读到的,我需要给文件访问权限,因此我定义了允许本地文件访问的选项。但是它仍然会抛出一堆奇怪的错误

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似乎发生在无法找到错误文件中加载的另一个文件时。这方面的一个例子是加载字体文件。

Bootstrap包含很多字体,它们会导致错误。

我也不知道如何让所有字体正确加载。

如果你只是用CSS读取字体,有一种方法可以将其转换为base64

最新更新