Creating and writing to a pdf file in Python

后端 未结 3 1477
醉话见心
醉话见心 2020-12-06 01:53

Why won\'t this work :

with open(\'file.pdf\', \'w\') as outfile:
    outfile.write(\"Hello\")

The code works fine, but the .pdf file cann

3条回答
  •  春和景丽
    2020-12-06 02:33

    you could install the fpdf library and then:

    from fpdf import FPDF
    
    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", border=0)
    pdf.output('test.pdf', 'F')
    

提交回复
热议问题