方法:python-pdfkit将网页(由JS生成)转换为PDF [英] Approach: python-pdfkit convert webpage(JS generated) into PDF
问题描述
views.py
def download_as_pdf(request):
# some stuff/function call to get updated(with data and JS) template and render it
return render(request, temp)
def download(request):
import pdfkit
pdfkit.from_url('/download/', 'out.pdf', options={'ignore-load-errors': None})
return HttpResponse('DONE')
urls.py
url(r'^download/', views.download_as_pdf, name="download_pdf")
我想在pdf中打印 / download /
url的所有内容(一些图表(JS生成的图表)。如果我输入这两行
I want to print all content(some graphs (JS generated - flotcharts)) of /download/
url in pdf. If I put these two lines
import pdfkit
pdfkit.from_url('/download/', 'out.pdf', options={'ignore-load-errors': None})
在 download_as_pdf
查看它不会以pdf格式打印任何内容(pdf虽然下载但为空)
(我认为是因为这些语句之后发生了模板渲染,这就是为什么?)
in download_as_pdf
view it prints nothing in pdf (pdf gets download though but empty)
(I think because template rendering happening after these statements thats why ??)
我应该如何继续在pdf中打印图形(我可以通过线程解决此问题吗?如何?)或其他任何方法
how should I proceed to prit graph in pdf (can I solve this by threading? how?) or any other approach
推荐答案
这可能是因为在加载整个javascript之前渲染了pdf。如果您引入了JavaScript延迟,那么它将起作用。
This could be because pdf is rendered before the entire javascript is loaded. If you introduce a javascript delay it will work.
options = {
'javascript-delay':'5000'
}
这篇关于方法:python-pdfkit将网页(由JS生成)转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!