python - pyfpdf write_html 内联 CSS 样式属性在 fpdf python 中不起作用

标签 python html css django fpdf

我正在尝试在 python Django 中使用 pyfpdf 创建一个 PDF 文件。下面的代码片段我正在尝试生成 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 - pyfpdf write_html 内联 CSS 样式属性在 fpdf python 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54588120/

相关文章:

python - 我如何调整我的代码,以便我的透明 python 图像在另一个图像(具有新的着色颜色)之上呈现为高质量?

python - Django:从 urls.py 获取网址名称

html - 水平对齐按钮

javascript - 如何使表格中的整个 <tr> 像 <a href =""> 一样可点击

javascript - 如何计算 HTML 元素的左边距

python - 我不确定 pygame.mixer.init 是否有效

python - 将全局值作为参数传递给装饰器和函数

页面上的 HTML 垂直可调整大小区域

html - 我怎样才能收缩图像以适应 parent 设定高度内的所有 flex child

javascript - 如何删除最后(动态)创建的元素?