CSS不是由Django中的Pisa的pdf生成的 [英] CSS not rendered by Pisa's pdf generation in Django
本文介绍了CSS不是由Django中的Pisa的pdf生成的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Pisa从HTML生成PDF文件:
I generate a pdf file from HTML using Pisa:
def fetch_resources(uri, rel):
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
return path
def write_pdf(template_src, context_dict, filename):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = open(filename, 'wb')
pdf = pisa.pisaDocument(StringIO.StringIO(
html.encode("UTF-8")), result, link_callback=fetch_resources)
result.close()
我的HTML有一个到外部CSS的链接,并且正确呈现,但是比萨没有使用CSS(例如字体大小,表格单元格宽度,文本-align ...)。
My HTML has a link to an external CSS and is rendered properly, but the CSS is not used by Pisa (eg. font size, table cell width, text-align...).
<!DOCTYPE html>
<html lang="fr">
<head>
<link rel="stylesheet" href="/site_media/style/style.css" />
</head>
<body>
....
我错过了什么吗?
感谢
推荐答案
您可以尝试 This is the Pisa-and-Reportlab-pitfalls'
我必须添加这个
You could try this 'Pisa-and-Reportlab-pitfalls' I had to add this
def fetch_resources(uri, rel):
除此之外,我仍然在模板中携带我的所有CSS。此外,请确保您使用的是 xhtml2pdf ,而不是旧的ho.pisa。
On top of that I still carry all my css within the template. Also make sure you're using xhtml2pdf and not the old ho.pisa.
这篇关于CSS不是由Django中的Pisa的pdf生成的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文