【问题标题】:pyfpdf write_html In-line CSS style attribute not working in fpdf pythonpyfpdf write_html 内联 CSS 样式属性在 fpdf python 中不起作用
【发布时间】:2019-02-08 08:00:12
【问题描述】:

我正在尝试在 python Django 中使用 pyfpdf 创建 PDF 文件。以下代码 sn-p 我正在尝试生成 HTML 代码的 pdf,并且我正在使用内联 CSS,但它没有呈现 css 样式

from fpdf import FPDF, HTMLMixin
import os

class WriteHtmlPDF(FPDF, HTMLMixin):
    pass

pdf = WriteHtmlPDF()
# First page
pdf.add_page()

html = f"""<h3>xxxxx</h3>
 <div style="border:1px solid #000">
     <table border="1" cellpadding="5" cellspacing="0">
         <tr><th width=20 align="left">xxxxxxxx:</th><td width="100">xxxxxxxx</td></tr>
         <tr><th width=20 align="left">xxxxxxxx:</th><td width="100">xxxxxxxxx</td></tr>
         <tr><th width=20 align="left">xxxxxxxx:</th><td width="100">xxxxxxxxx</td></tr>
         <tr><th width=20 align="left">xxxxxxxx:</th><td width="100">xxxxxxxxx</td></tr>
     </table>
 </div>
 <div style="border: 1px solid; padding: 2px; font-size: 12px;">
     <table>
         <tr>
             <td width="20">xxxxxx: 1</td>
             <td width="20">xxxxxx: 0</td>
             <td width="20">xxxxxx: 1</td>
         </tr>
     </table>
 </div>"""

生成了 PDF 文件,但没有 CSS 样式。

【问题讨论】:

    标签: python html css django fpdf


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 2013-12-06
    • 2020-03-19
    • 2012-01-15
    • 2017-10-21
    相关资源
    最近更新 更多