You are on page 1of 113

Search

Write
Sign up
Sign in

Member-only story

How to Create PDF Reports with Python —


The Essential Guide

Create PDF reports with beautiful visualizations in 10 minutes or less


Dario Radečić

Follow

·
768

4
Photo by Jesse G-C on Unsplash
Reports are everywhere, so any tech professional must know how to create them. It’s a tedious

and time-consuming task, which makes it a perfect candidate for automation with Python.

You can benefit from an automated report generation whether you’re a data scientist or a

software developer. For example, data scientists might use reports to show performance or

explanations of machine learning models.

This article will teach you how to make data-visualization-based reports and save them as PDFs.

To be more precise, you’ll learn how to combine multiple data visualizations (dummy sales data)

into a single PDF file.

And the best thing is — it’s easier than you think!


The article is structured as follows:

● Data generation

● Data visualization

● Create a PDF page structure

● Create PDF reports

● Conclusion

You can download the Notebook with the source code here.

Data generation
You can’t have reports without data. That’s why you’ll have to generate some first — more on that

in a bit.

Let’s start with the imports. You’ll need a bunch of things — but the FPDF library is likely the only

unknown. Put simply, it’s used to create PDFs, and you’ll work with it a bit later. Refer to the

following snippet for the imports:

Let’s generate some fake data next. The idea is to declare a function that returns a data frame of

dummy sales data for a given month. It does that by constructing a date range for the entire

month and then assigning the sales amount as a random integer within a given range.

You can use the calendar library to get the last day for any year/month combination. Here’s…
Create an account to read the full story.

The author made this story available to Medium members only.


If you’re new to Medium, create a new account to read this story on us.

Sign up with Google

Sign up with Facebook

Sign up with email


Already have an account? Sign in

768

Written by Dario Radečić


42K Followers
·

Writer for

Towards Data Science


Data Scientist & Tech Writer | betterdatascience.com
Follow

More from Dario Radečić and Towards Data Science

Dario Radečić
in

Level Up Coding

Top 5 Orchestration Tools in 2023


You never had more options when it comes to choosing an orchestration platform — Here’s a curated list for 2023 and beyond.
14 min read
·
Oct 30
626
18

Rahul Nayak

in
Towards Data Science

How to Convert Any Text Into a Graph of Concepts


A method to convert any text corpus into a Knowledge Graph using Mistral 7B.
12 min read
·
Nov 10
4.6K
42
Pau Blasco i Roca

in

Towards Data Science


My Life Stats: I Tracked My Habits for a Year, and This Is What I Learned
I measured the time I spent on my daily activities (studying, doing sports, socializing, sleeping…) for 332 days in a row.
12 min read
·
Nov 21
4.7K
84
Dario Radečić

in

Geek Culture

Airflow vs. Prefect vs. Kestra — Which is Best for Building Advanced Data Pipelines?
Remote REST API + S3 + Remote Postgres Database — This data pipeline covers an advanced use case comparison between
Airflow, Prefect, and…
14 min read
·
Jul 24
177
3
See all from Dario Radečić
See all from Towards Data Science

Recommended from Medium


chatur priyono

Simplifying Data Extraction: How to Convert PDF to Excel using Python and Tabula

Introduction: PDF files are commonly used for sharing documents, but extracting data from them can be a tedious task,
especially when you…

2 min read

Jun 21
Rahul Nayak

in

Towards Data Science


How to Convert Any Text Into a Graph of Concepts

A method to convert any text corpus into a Knowledge Graph using Mistral 7B.

12 min read

Nov 10

4.6K

42
Lists
Predictive Modeling w/ Python

20 stories

696 saves
Practical Guides to Machine Learning

10 stories

793 saves

Coding & Development


11 stories

325 saves

General Coding Knowledge

20 stories

686 saves
Ava

in

Python in Plain English

10 Reasons Python Could Be Outpaced by 2025


What Every Programmer Should Know
·
3 min read
·
5 days ago
34
1
Manoj Das

Tabulate: Your Go-To Solution for Stylish Tables in Python


What is Tabulate? How to create formatted tabular data in Python.
👉
7 min read
·
Aug 19
13
Renu Khandelwal

Achieving Peak Performance: Python Coding Strategies


Advanced Python Techniques for Memory and Time Efficiency
·
11 min read
·
4 days ago
59
1
Bex T.

in

Towards AI

10 Advanced Matplotlib Concepts You Must Know To Create Killer Visuals


Become Leonardo da Matplotlib
·
9 min read
·
Jun 30
1.1K
8
See more recommendations
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams
Search
Write
Sign up
Sign in

Member-only story

How to Create PDF Reports with Python —


The Essential Guide

Create PDF reports with beautiful visualizations in 10 minutes or less


Dario Radečić

Follow

·
768

4
Photo by Jesse G-C on Unsplash
Reports are everywhere, so any tech professional must know how to create them. It’s a tedious

and time-consuming task, which makes it a perfect candidate for automation with Python.

You can benefit from an automated report generation whether you’re a data scientist or a

software developer. For example, data scientists might use reports to show performance or

explanations of machine learning models.

This article will teach you how to make data-visualization-based reports and save them as PDFs.

To be more precise, you’ll learn how to combine multiple data visualizations (dummy sales data)

into a single PDF file.

And the best thing is — it’s easier than you think!


The article is structured as follows:

● Data generation

● Data visualization

● Create a PDF page structure

● Create PDF reports

● Conclusion

You can download the Notebook with the source code here.

Data generation
You can’t have reports without data. That’s why you’ll have to generate some first — more on that

in a bit.

Let’s start with the imports. You’ll need a bunch of things — but the FPDF library is likely the only

unknown. Put simply, it’s used to create PDFs, and you’ll work with it a bit later. Refer to the

following snippet for the imports:

Let’s generate some fake data next. The idea is to declare a function that returns a data frame of

dummy sales data for a given month. It does that by constructing a date range for the entire

month and then assigning the sales amount as a random integer within a given range.

You can use the calendar library to get the last day for any year/month combination. Here’s…
Create an account to read the full story.

The author made this story available to Medium members only.


If you’re new to Medium, create a new account to read this story on us.

Sign up with Google

Sign up with Facebook

Sign up with email


Already have an account? Sign in

768

Written by Dario Radečić


42K Followers
·

Writer for

Towards Data Science


Data Scientist & Tech Writer | betterdatascience.com
Follow

More from Dario Radečić and Towards Data Science

Dario Radečić
in

Level Up Coding

Top 5 Orchestration Tools in 2023


You never had more options when it comes to choosing an orchestration platform — Here’s a curated list for 2023 and beyond.
14 min read
·
Oct 30
626
18

Rahul Nayak

in
Towards Data Science

How to Convert Any Text Into a Graph of Concepts


A method to convert any text corpus into a Knowledge Graph using Mistral 7B.
12 min read
·
Nov 10
4.6K
42
Pau Blasco i Roca

in

Towards Data Science


My Life Stats: I Tracked My Habits for a Year, and This Is What I Learned
I measured the time I spent on my daily activities (studying, doing sports, socializing, sleeping…) for 332 days in a row.
12 min read
·
Nov 21
4.7K
84
Dario Radečić

in

Geek Culture

Airflow vs. Prefect vs. Kestra — Which is Best for Building Advanced Data Pipelines?
Remote REST API + S3 + Remote Postgres Database — This data pipeline covers an advanced use case comparison between
Airflow, Prefect, and…
14 min read
·
Jul 24
177
3
See all from Dario Radečić
See all from Towards Data Science

Recommended from Medium


chatur priyono

Simplifying Data Extraction: How to Convert PDF to Excel using Python and Tabula

Introduction: PDF files are commonly used for sharing documents, but extracting data from them can be a tedious task,
especially when you…

2 min read

Jun 21
Rahul Nayak

in

Towards Data Science


How to Convert Any Text Into a Graph of Concepts

A method to convert any text corpus into a Knowledge Graph using Mistral 7B.

12 min read

Nov 10

4.6K

42
Lists
Predictive Modeling w/ Python

20 stories

696 saves
Practical Guides to Machine Learning

10 stories

793 saves

Coding & Development


11 stories

325 saves

General Coding Knowledge

20 stories

686 saves
Ava

in

Python in Plain English

10 Reasons Python Could Be Outpaced by 2025


What Every Programmer Should Know
·
3 min read
·
5 days ago
34
1
Manoj Das

Tabulate: Your Go-To Solution for Stylish Tables in Python


What is Tabulate? How to create formatted tabular data in Python.
👉
7 min read
·
Aug 19
13
Renu Khandelwal

Achieving Peak Performance: Python Coding Strategies


Advanced Python Techniques for Memory and Time Efficiency
·
11 min read
·
4 days ago
59
1
Bex T.

in

Towards AI

10 Advanced Matplotlib Concepts You Must Know To Create Killer Visuals


Become Leonardo da Matplotlib
·
9 min read
·
Jun 30
1.1K
8
See more recommendations
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams
Search

Write
Sign up
Sign in

Member-only story

How to Create PDF Reports with Python —


The Essential Guide

Create PDF reports with beautiful visualizations in 10 minutes or less


Dario Radečić

Follow

·
768

4
Photo by Jesse G-C on Unsplash
Reports are everywhere, so any tech professional must know how to create them. It’s a tedious

and time-consuming task, which makes it a perfect candidate for automation with Python.

You can benefit from an automated report generation whether you’re a data scientist or a

software developer. For example, data scientists might use reports to show performance or

explanations of machine learning models.

This article will teach you how to make data-visualization-based reports and save them as PDFs.

To be more precise, you’ll learn how to combine multiple data visualizations (dummy sales data)

into a single PDF file.

And the best thing is — it’s easier than you think!


The article is structured as follows:

● Data generation

● Data visualization

● Create a PDF page structure

● Create PDF reports

● Conclusion

You can download the Notebook with the source code here.

Data generation
You can’t have reports without data. That’s why you’ll have to generate some first — more on that

in a bit.

Let’s start with the imports. You’ll need a bunch of things — but the FPDF library is likely the only

unknown. Put simply, it’s used to create PDFs, and you’ll work with it a bit later. Refer to the

following snippet for the imports:

Let’s generate some fake data next. The idea is to declare a function that returns a data frame of

dummy sales data for a given month. It does that by constructing a date range for the entire

month and then assigning the sales amount as a random integer within a given range.

You can use the calendar library to get the last day for any year/month combination. Here’s…
Create an account to read the full story.

The author made this story available to Medium members only.


If you’re new to Medium, create a new account to read this story on us.

Sign up with Google

Sign up with Facebook

Sign up with email


Already have an account? Sign in

768

Written by Dario Radečić


42K Followers
·

Writer for

Towards Data Science


Data Scientist & Tech Writer | betterdatascience.com
Follow

More from Dario Radečić and Towards Data Science

Dario Radečić
in

Level Up Coding

Top 5 Orchestration Tools in 2023


You never had more options when it comes to choosing an orchestration platform — Here’s a curated list for 2023 and beyond.
14 min read
·
Oct 30
626
18

Rahul Nayak

in
Towards Data Science

How to Convert Any Text Into a Graph of Concepts


A method to convert any text corpus into a Knowledge Graph using Mistral 7B.
12 min read
·
Nov 10
4.6K
42
Pau Blasco i Roca

in

Towards Data Science


My Life Stats: I Tracked My Habits for a Year, and This Is What I Learned
I measured the time I spent on my daily activities (studying, doing sports, socializing, sleeping…) for 332 days in a row.
12 min read
·
Nov 21
4.7K
84
Dario Radečić

in

Geek Culture

Airflow vs. Prefect vs. Kestra — Which is Best for Building Advanced Data Pipelines?
Remote REST API + S3 + Remote Postgres Database — This data pipeline covers an advanced use case comparison between
Airflow, Prefect, and…
14 min read
·
Jul 24
177
3
See all from Dario Radečić
See all from Towards Data Science

Recommended from Medium


chatur priyono

Simplifying Data Extraction: How to Convert PDF to Excel using Python and Tabula

Introduction: PDF files are commonly used for sharing documents, but extracting data from them can be a tedious task,
especially when you…

2 min read

Jun 21
Rahul Nayak

in

Towards Data Science


How to Convert Any Text Into a Graph of Concepts

A method to convert any text corpus into a Knowledge Graph using Mistral 7B.

12 min read

Nov 10

4.6K

42
Lists
Predictive Modeling w/ Python

20 stories

696 saves
Practical Guides to Machine Learning

10 stories

793 saves

Coding & Development


11 stories

325 saves

General Coding Knowledge

20 stories

686 saves
Ava

in

Python in Plain English

10 Reasons Python Could Be Outpaced by 2025


What Every Programmer Should Know
·
3 min read
·
5 days ago
34
1
Manoj Das

Tabulate: Your Go-To Solution for Stylish Tables in Python


What is Tabulate? How to create formatted tabular data in Python.
👉
7 min read
·
Aug 19
13
Renu Khandelwal

Achieving Peak Performance: Python Coding Strategies


Advanced Python Techniques for Memory and Time Efficiency
·
11 min read
·
4 days ago
59
1
Bex T.

in

Towards AI

10 Advanced Matplotlib Concepts You Must Know To Create Killer Visuals


Become Leonardo da Matplotlib
·
9 min read
·
Jun 30
1.1K
8
See more recommendations
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams
Search

Write
Sign up
Sign in

Member-only story

How to Create PDF Reports with Python —


The Essential Guide

Create PDF reports with beautiful visualizations in 10 minutes or less


Dario Radečić

Follow

·
768

4
Photo by Jesse G-C on Unsplash
Reports are everywhere, so any tech professional must know how to create them. It’s a tedious

and time-consuming task, which makes it a perfect candidate for automation with Python.

You can benefit from an automated report generation whether you’re a data scientist or a

software developer. For example, data scientists might use reports to show performance or

explanations of machine learning models.

This article will teach you how to make data-visualization-based reports and save them as PDFs.

To be more precise, you’ll learn how to combine multiple data visualizations (dummy sales data)

into a single PDF file.

And the best thing is — it’s easier than you think!


The article is structured as follows:

● Data generation

● Data visualization

● Create a PDF page structure

● Create PDF reports

● Conclusion

You can download the Notebook with the source code here.

Data generation
You can’t have reports without data. That’s why you’ll have to generate some first — more on that

in a bit.

Let’s start with the imports. You’ll need a bunch of things — but the FPDF library is likely the only

unknown. Put simply, it’s used to create PDFs, and you’ll work with it a bit later. Refer to the

following snippet for the imports:

Let’s generate some fake data next. The idea is to declare a function that returns a data frame of

dummy sales data for a given month. It does that by constructing a date range for the entire

month and then assigning the sales amount as a random integer within a given range.

You can use the calendar library to get the last day for any year/month combination. Here’s…
Create an account to read the full story.

The author made this story available to Medium members only.


If you’re new to Medium, create a new account to read this story on us.

Sign up with Google

Sign up with Facebook

Sign up with email


Already have an account? Sign in

768

Written by Dario Radečić


42K Followers
·

Writer for

Towards Data Science


Data Scientist & Tech Writer | betterdatascience.com
Follow

More from Dario Radečić and Towards Data Science

Dario Radečić
in

Level Up Coding

Top 5 Orchestration Tools in 2023


You never had more options when it comes to choosing an orchestration platform — Here’s a curated list for 2023 and beyond.
14 min read
·
Oct 30
626
18

Rahul Nayak

in
Towards Data Science

How to Convert Any Text Into a Graph of Concepts


A method to convert any text corpus into a Knowledge Graph using Mistral 7B.
12 min read
·
Nov 10
4.6K
42
Pau Blasco i Roca

in

Towards Data Science


My Life Stats: I Tracked My Habits for a Year, and This Is What I Learned
I measured the time I spent on my daily activities (studying, doing sports, socializing, sleeping…) for 332 days in a row.
12 min read
·
Nov 21
4.7K
84
Dario Radečić

in

Geek Culture

Airflow vs. Prefect vs. Kestra — Which is Best for Building Advanced Data Pipelines?
Remote REST API + S3 + Remote Postgres Database — This data pipeline covers an advanced use case comparison between
Airflow, Prefect, and…
14 min read
·
Jul 24
177
3
See all from Dario Radečić
See all from Towards Data Science

Recommended from Medium


chatur priyono

Simplifying Data Extraction: How to Convert PDF to Excel using Python and Tabula

Introduction: PDF files are commonly used for sharing documents, but extracting data from them can be a tedious task,
especially when you…

2 min read

Jun 21
Rahul Nayak

in

Towards Data Science


How to Convert Any Text Into a Graph of Concepts

A method to convert any text corpus into a Knowledge Graph using Mistral 7B.

12 min read

Nov 10

4.6K

42
Lists
Predictive Modeling w/ Python

20 stories

696 saves
Practical Guides to Machine Learning

10 stories

793 saves

Coding & Development


11 stories

325 saves

General Coding Knowledge

20 stories

686 saves
Ava

in

Python in Plain English

10 Reasons Python Could Be Outpaced by 2025


What Every Programmer Should Know
·
3 min read
·
5 days ago
34
1
Manoj Das

Tabulate: Your Go-To Solution for Stylish Tables in Python


What is Tabulate? How to create formatted tabular data in Python.
👉
7 min read
·
Aug 19
13
Renu Khandelwal

Achieving Peak Performance: Python Coding Strategies


Advanced Python Techniques for Memory and Time Efficiency
·
11 min read
·
4 days ago
59
1
Bex T.

in

Towards AI

10 Advanced Matplotlib Concepts You Must Know To Create Killer Visuals


Become Leonardo da Matplotlib
·
9 min read
·
Jun 30
1.1K
8
See more recommendations
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams

You might also like