Creating and writing to a pdf file in Python

后端 未结 3 1487
醉话见心
醉话见心 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:27

    What's the difference between a normal text file and pdf?

    A PDF file has a specific format. You can read more here. A text is a much simpler file, thus when you attempt to open a file that you think it's a PDF, but doesn't have this format, the file cannot be opened.

    What to do if I want to create and write to a pdf file in python?

    You need to use a module, like PyPDF2, Reportlab or FPDF. Moreover read Python PDF library.

提交回复
热议问题