PyFPDF返回空白页Python 2.7

2024-04-25 22:39:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Flask试用python2.7中的PyFPDF库。我通过pip安装了pyFPDF。但是,它并没有返回pdf,而是返回一个空白页。我没有收到任何错误。我是不是漏了字体?我只是想用Arial。这是我的密码:

@pdf.route('/pdf/<int:id>/pdf')
def pdf(id):

    id = str(id)

    pdf = FPDF()
    pdf.add_page()
    pdf.set_xy(0, 0)
    pdf.set_font('arial', 'B', 13.0)
    pdf.cell(ln=0, h=5.0, align='L', w=0, txt="Hello" + id, border=0)
    return pdf.output('test.pdf', 'F')

这是我的模板中的链接,我用它来触发PDF下载

<a href="{{ url_for('pdf.pdf', id=id) }}" class='btn pull-right margin-bottom'>
<i class="material-icons">picture_as_pdf</i> Export PDF
     </a>

上面的代码返回一个空白页。你知道吗


Tags: pipid密码flaskpdf错误字体route

热门问题