Other resources with pyFPDF examples

These are the very few good resources to start learning to use pyFPDF on your own:

Those are not the only resources available in the Web that mention or present pyFPDF examples, but they are the best, in my opinion at least.

I wrote the book about pyFPDF because I could not find any more resources to help me with the particular needs of my projects.  I had to study the code to accomplish some things and that helped to also contribute a bit of code to the project.

I hope this blog will also become a resource for developers starting to use pyFPDF. Some of the material of the book is already published here and answers many common questions about how to use the library. Feel free to explore the blog and download the book sample which already has a lot on useful information and code.




Tip: Check if new page will be added

To check in pyfpdf if a new page will be added after a cell of text, compare the current vertical position of the document to the “page_break_trigger” property.

# Import FPDF class
from fpdf import FPDF

# Create instance of FPDF class
# Letter size paper, use inches as unit of measure
pdf=FPDF(format='letter', unit='in')

# Add new page. Without this you cannot create the document.

# Remember to always put one of these at least once.

# Effective page width, or just epw
epw = pdf.w - 2*pdf.l_margin

# You should know the cell text height in the document's unit

text_height = 0.15 # inches in this case

for i in xrange(100):
    if (pdf.y + text_height > pdf.page_break_trigger):
        # If you write the cell you will jump
        # to a new page

        pdf.cell(2.0, text_height, "I am in a new page")
        pdf.cell(2.0, text_height, "My text")