Python does PDF: pyFPDF
Minimum price
Suggested price

Python does PDF: pyFPDF

About the Book

Follow book updates at @edwood_ocasio

Through this book I hope to share my hard earned knowledge about generating PDF documents dynamically using Python and libraries like pyFPDF, the main subject of this book.

If you are a busy professional developer like I am you do not want to spend too much time reading through lots of explanations. You want to get to the solution to your problem fast. That is why this book is written in cookbook style divided in some common themes. Most of the explaining will be done in the code's comments. The free sample already provides around 30 useful code examples!

I consider the book complete in the sense that it already covers basic and advanced topics about the most used features of pyFPDF.  However, the content will keep expanding.  I am actively working with the library in actual client's projects and I will share with book buyers any new knowledge, trick or hack I learn.

This book can help you add more value to client's projects that require generating PDF reports and, hopefully, that will mean more time and money for you.

About the Author

Edwood Ocasio
Edwood Ocasio

Developer with 20+ years of experience in different programming languages and industries.  Python is currently my main business programming language and I make a living thanks to it. For the same amount of years teached college level computers, software development and mathematics.

Table of Contents

  • Introduction
  • Installation
  • Writing text
    • Hello World!
    • Change paper format to Letter and units to inches
    • Text color
    • Text color by color hex values using hex2dec function
    • Text color by color names using webcolors module
    • Change font family and style
    • Text alignment and borders
    • Positioning text cells (boxes)
      • Using empty text cells to place other text cells
      • Using the effective page width to distribute content evenly
      • Using the effective page width to center text across a page
      • Using method set_xy() to exactly position a text cell
    • Wrapping text automatically (multi_cell)
      • Simple use of multi_cell
    • Putting two adjacent multi_cell blocks
    • Three adjacent multi cell columns
    • Coloring multi_cell blocks
    • Adjust cell width and height exactly to the text
    • Margins
      • Default margins
      • Changing margins
    • Mix page orientations
  • Tables
    • Table with horizontal lines at top and bottom
    • Table with horizontal lines after every row
    • Table with alternate row colors
    • Table using HTML and write_html
    • Table with vertical and horizontal lines
    • Table using only cell borders
    • Simple table class
  • Images
    • Image dimensions
    • Image types supported
    • Image positioning
    • Images with borders
    • Images in tables
    • Build a PDF with images in folder
    • Images as watermarks
      • Single page
      • Every page
  • Templates
    • The Visual Template Designer
      • Designer Toolbar
    • Replicating a document from a scanned image
      • Insert document background
      • Insert text elements
      • Preview PDF document
      • The template file
      • The code to fill the template
    • Clearing template contents before processing
    • Modifying template’s elements at runtime
    • Templates with more than one page
  • Generating PDFs in web applications
    • Using web2py
    • Using flask
  • Protecting with password a PDF
    • Generating a password protected PDF file
    • PDF protection inside a web2py web application
    • PDF protection inside a flask web application
  • One liners
    • Empty PDF document
    • Hello PDF document
    • Convert text file to PDF
    • Directory listing as a PDF, using multi_cell
    • From standard input to PDF

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub