简体   繁体   English

CSS不是由Dja的Pisa的pdf生成渲染的

[英]CSS not rendered by Pisa's pdf generation in Django

I generate a pdf file from HTML using Pisa: 我使用Pisa从HTML生成pdf文件:

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()

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...). 我的HTML有一个外部CSS的链接,并且正确呈现,但比萨不使用CSS(例如字体大小,表格单元格宽度,文本对齐...)。

<!DOCTYPE html>
<html lang="fr">
<head>
    <link rel="stylesheet" href="/site_media/style/style.css" />
</head>

<body>
....

Did I miss something? 我错过了什么?

Thanks 谢谢

You could try this 'Pisa-and-Reportlab-pitfalls' I had to add this 你可以试试这个'Pisa-and-Reportlab-pitfalls'我必须加上这个

def fetch_resources(uri, rel):

On top of that I still carry all my css within the template. 最重要的是,我仍然在模板中携带所有的CSS。 Also make sure you're using xhtml2pdf and not the old ho.pisa. 还要确保你使用的是xhtml2pdf而不是旧的ho.pisa。

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

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