ReportLab: PDF Processing with Python

ReportLab: PDF Processing with Python

ReportLab is the primary package that most Python developers use for creating PDFs programmatically. This book will take a deep dive into this package and teaches you how to use this versatile library.

Cover art by Therese Larsson. See more from her on Silly Beast Illustration or Behance.

You can purchase this book in Paperback or Kindle on Amazon or as an eBook (PDF, epub and mobi) on Leanpub.

This book covers the following topics:

  • Creating PDFs with ReportLab Canvas methods
  • Using PLATYPUS in ReportLab for Dynamic Reports
  • Turning Data into Reports with ReportLab
  • Splitting / Joining PDFs with PyPDF2 and pdfrw
  • Rotating Pages
  • PDF Security
  • Merging PDFs
  • and much, much more!

Full Table of Contents

  • Introduction
    • About the Author
    • Conventions
    • Setting up & Activating a Virtual Environment
    • Dependencies
    • Installation
    • Configuration
    • Reader Feedback
    • Errata
    • Code Examples
  • Part I – The ReportLab Toolkit
  • Chapter 1 – Getting Started with Reportlab
    • The Canvas Object
    • Canvas Methods
    • Using Colors in ReportLab
    • Adding a Photo
    • The textobject
    • Create a Page Break
    • Canvas Orientation (Portrait vs. Landscape)
    • Other methods
    • A Simple Sample Application
    • Wrapping Up
  • Chapter 2 – ReportLab and Fonts
    • Unicode / UTF8 is the Default
    • The Standard Fonts
    • Other Type-1 Fonts
    • TrueType Fonts
    • Asian Fonts
    • Switching Between Fonts
    • Wrapping Up
  • Chapter 3 – Intro to Page Layout
    • The Basics of PLATYPUS
    • Changing Fixed Elements Across Pages
    • Flowable Methods
    • Frame Basics
    • Templates
    • Flowable Orientation (Portrait vs. Landscape)
    • Wrapping Up
  • Chapter 4 – Paragraphs
    • Paragraph Styles
    • Paragraph Markup Tags
    • The Outermost Markup Tags
    • Using Intra-Paragraph Markup
    • Working with Fonts
    • Superscripts & Subscripts
    • Inserting Inline Images
    • Numbering Paragraphs / Sections
    • Bullets
    • Wrapping Up
  • Chapter 5 – Tables
    • The Table’s Methods
    • Applying Style to Your Table
    • Cell Formatting
    • Changing Fonts in Tables
    • Line Commands
    • Cell Alignment
    • Alternating Background Colors
    • Putting Paragraphs in Your Cells
    • Adding Images to Cells
    • Spanning
    • Wrapping Up
  • Chapter 6 – Other Flowables
    • Preformatted
    • XPreformatted
    • The Image Flowable
    • The Spacer Flowable
    • PageBreak
    • CondPageBreak
    • KeepTogether
    • How to Add a Table of Contents
    • SimpleIndex
    • ListFlowable / ListItem
    • Wrapping Up
  • Chapter 7 – Creating Your Own Flowables
    • Creating a Line Flowable
    • Creating a Bordered Textbox + Line Flowable
    • Modifying a Pre-Existing Flowable
    • Wrapping Up
  • Chapter 8 – Intro to Graphics and Charts
    • What is a Drawing?
    • ReportLab’s Renderers
    • The Coordinate System
    • A Simple Drawing
    • Supported Outputs
    • Verifying Attributes
    • Naming Shapes
    • Charts and Graphs
    • Labels
    • Axes
    • Bar Charts
    • Line Charts
    • Line Plots
    • Pie Charts
    • Adding Titles and Legends
    • Odds and Ends
    • Wrapping Up
  • Chapter 9 – Other Graphics
    • Shapes
    • Widgets
    • Bar Codes
    • Wrapping Up
  • Chapter 10 – Creating Special Features in Your PDF
    • File Annotations
    • Bookmarks
    • Page Transitions
    • Encryption
    • Interactive Forms
    • Wrapping Up
  • Part II – Tutorials and How-Tos
  • Chapter 11 – Turning Data into PDFs
    • Getting Started
    • Creating the Base Template Class
    • Refactoring the EOB Class
    • Creating a Multipage Document
    • Using Real Data
    • Consuming XML
    • Wrapping Up
  • Chapter 12 – Custom Headers and Footers
    • A Naive Header
    • Putting the Header on Every Page
    • Adding a Logo
    • Configurable Logos
    • Adding Page Numbers
    • Adding a Page Number of Total
    • Headers + Footers
    • Wrapping Up
  • Chapter 13 – Creating a PDF Library
    • Accepting Different Data Formats
    • Multipage Data Files
    • Custom Stylesheets
    • Configuring Your Application
    • Adding a Graphical User Interface
    • Finishing the User Interface
    • Wrapping Up
  • Chapter 14 – The PyPDF2 Package
    • Installation
    • Extracting Metadata from PDFs
    • Extracting Text from PDFs
    • Splitting PDFs
    • Merging Multiple PDFs Together
    • Rotating Pages
    • Overlaying / Watermarking Pages
    • PDF Encryption
    • Wrapping Up
  • Chapter 15 – The pdfrw Package
    • Installation
    • Extracting Information from PDF
    • Splitting
    • Merging / Concatenating
    • Rotating
    • Overlaying / Watermarking Pages
    • Scaling
    • Combining pdfrw and ReportLab
    • Wrapping Up
  • Chapter 16 – Extracting and Exporting Data from PDFs
    • Extracting Text with PDFMiner
    • Exporting Text via pdf2txt.py
    • Extracting Text with Slate
    • Exporting Your Data
    • Exporting to XML
    • Exporting to JSON
    • Exporting to CSV
    • Extracting Images
    • Wrapping Up
  • Chapter 17 – Filling in PDF Forms
    • Creating a Simple Form
    • Merging Overlays
    • Other Ways to Fill Forms
    • Using the pdfforms Package
    • Wrapping Up
  • Chapter 18 – Converting Markup to PDF
    • rst2pdf
    • WeasyPrint
    • Pandoc
    • LaTeX
    • Wrapping Up
  • Chapter 19 – The PyFPDF Package
    • Installation
    • Basic Usage
    • Working with Fonts
    • Drawing
    • Adding Images
    • Multipage Documents
    • Headers and Footers
    • Tables
    • Transform HTML to PDF
    • Web2Py
    • Templates
    • Wrapping Up
  • Appendix A – Adding SVG Files in ReportLab
    • Dependencies
    • Installation
    • Usage
    • Drawing on the Canvas
    • Adding an SVG to a Flowable
    • Scaling SVGs in ReportLab
    • Using SVG Plots from matplotlib in ReportLab
    • Using svg2pdf
    • Wrapping Up
  • Appendix B – Getting System Fonts
    • The fontTools Package
    • Getting the System’s Fonts
    • Wrapping Up
  • Appendix C – Creating a Color Demo
    • Getting the Colors
    • Wrapping Up
  • Afterword and Thanks