reingart / pyfpdf

Simple PDF generation for Python (FPDF PHP port)
https://code.google.com/p/pyfpdf/
GNU Lesser General Public License v3.0
848 stars 513 forks source link

bytes output actually outputs str #220

Open dmwyatt opened 3 months ago

dmwyatt commented 3 months ago
from fpdf import FPDF
def create_minimal_pdf():
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font('Arial', 'B', 12)
    pdf.cell(0, 10, 'Title of the PDF', 0, 1, 'C')
    pdf.set_font('Arial', '', 12)
    pdf.multi_cell(0, 10, 'This is a minimal PDF generated using the FPDF library in Python. '
                          'FPDF is a PHP class which allows to generate PDF files with pure PHP, '
                          'that is to say without using the PDFlib library. FPDF offers all the '
                          'functions needed to generate a PDF file. Here is a simple example.')
    return pdf.output(dest="S")
>>> print(type(create_minimal_pdf()))
<class 'str'>
Lucas-C commented 3 months ago

Hi @dmwyatt 🙂

Note that PyFPDF is not maintained anymore. See #207. fpdf2 is its successor: https://pypi.org/project/fpdf2/ On GitHub it's there: https://github.com/py-pdf/fpdf2

If you are using pip, switching is very easy:

pip uninstall pypdf
pip install fpdf2

The output of your script will then be:

<class 'bytearray'>

You will also see a few DeprecationWarning warnings explaining what changed compared to PyPDF 🙂