Python 3 ReportLab Library Script to Export Colorful Invoice Billing Data Table in PDF & Save it
38 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-reportlab-library-script-to-export-colorful-invoice-billing-data-table-in-pdf-save-it/
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you how to
0:04
generate a invoice billing data inside
0:09
your PDF document with your company name
0:12
and a table of products of your which of
0:15
your company whatever products your
0:17
company is selling so some simply like a
0:20
invoice data document inside PDF
0:23
document so inside this Python script so
0:26
I've written this Python script here uh
0:28
which will actually generate this
0:29
colorful PDF document which will contain
0:32
the
0:33
data inside the tablo structure uh let
0:37
me just execute this python
0:39
script and as soon as I execute this go
0:43
to the terminal and just type here
0:45
python app py so you will see on the
0:48
left hand side it will create a file
0:52
which is uh
0:53
recept you will see the file has been
0:56
created and if I try to open this file
0:58
you will see it will look something like
1:00
this this will be the
1:02
output uh first of all your company name
1:05
whatever is your company name then we
1:07
have this tabular structure a
1:10
table invoice table holding data of
1:15
whatever products that you have
1:17
purchased we also have the date here
1:21
alongside with the product at which date
1:24
you have purchased it and what is the
1:26
price of it it is a subscription how
1:29
much time that you have purchased it
1:32
this is a price here so it also
1:34
calculates the total number of price in
1:36
the invoice document right here you will
1:38
see
1:40
that so we have generated this PDF
1:43
document using report lab library inside
1:45
Python which is an open-source library
1:48
for generating PDF documents so you can
1:51
everything you can customize it inside
1:53
this PDF document i will show you the
1:56
script so now to get started here first
1:59
of all you need to uh require this
2:02
package you need to require this or
2:04
install this package which is report lab
2:10
so the command is very simple pip
2:13
install report lab this is the command i
2:15
have already installed it so after
2:18
installing it
2:20
uh I have given all this source code is
2:23
in the uh description of this video so
2:27
the source code is
2:31
given so now I will show you all this
2:34
source code step by step
2:40
so first of all you need to require all
2:44
the packages that you will need for this
2:46
application so for requiring it you
2:48
simply write here from report lab and
2:52
then like this we need to import this
2:56
simple doc template and we also need to
2:59
require the table as well because we'll
3:02
be embedding tables as well and we also
3:04
need to require paragraph so these are
3:07
all the elements that we will be
3:09
inserting inside the PDF document and
3:11
also table
3:14
style and then we also need to say from
3:18
report
3:22
lab dot lib we need to
3:26
import the colors the different kinds of
3:30
colors so this will be a colorful table
3:32
so for we need to import colors and
3:37
similarly from report
3:39
lab.lib dotpage sizes we need to import
3:44
the A4 size so there are different sizes
3:47
available inside the PDF document so we
3:50
need to import the correct size which is
3:52
A4 size after that we again need to say
3:55
from report lab dot lib dotstyles we
4:00
need to import get sample
4:03
stylesheet so now all the packages have
4:07
been in imported now we just need to
4:09
make sure we provide the correct data
4:12
for our
4:14
invoice
4:16
so this data can can be anything so I'm
4:21
just copy pasting the data here
4:24
so once you get the script you can
4:27
modify this data so this is actually
4:29
having this uh three columns right here
4:32
date name subscription price and then we
4:35
have a series of products right
4:37
here like this subtotal discount total
4:41
so this is very similar uh invoice
4:45
document how many products have you
4:47
purchased what is the price of it what
4:49
is the discount uh what is the total
4:52
price everything so after providing this
4:56
we will now be generating the PDF
4:58
document for generating the PDF document
5:00
we simply initialize this simple
5:04
doc template we initialize this and
5:07
inside this it actually takes the first
5:11
argument as
5:12
the name of the file so we will simply
5:15
provide this as result PDF the name of
5:18
the PDF file and then the second
5:21
argument will be the page size so
5:23
whatever is the page size that you want
5:25
to configure so in my case I will be
5:28
configuring A4 size so
5:33
simply so now after generating the PDF
5:37
we just need
5:38
to also style it for styling it we will
5:42
use this get sample stylesheet method
5:45
that we imported earlier on we also need
5:48
to set the title as well of the for
5:52
setting the title we use
5:55
this heading
6:03
one and then we can set the alignment of
6:06
the heading which will be in the center
6:08
position so we setting this alignment
6:10
value to one some more properties are
6:14
also there which is font size font name
6:16
you can even change these properties as
6:18
well by changing this and then we can
6:22
add this simple
6:25
paragraph so you will see we are setting
6:28
this as free media tools which is your
6:30
company name so this will be your title
6:33
and then we add
6:37
the table by using this table style
6:43
and here you specify your tabular
6:48
structure so this will contain the CSS
6:52
styles as well so here we are providing
6:55
different CSS properties here such as
6:57
the what is what will be the background
7:00
color what will be the text color what
7:02
will be the alignment of the table
7:04
background everything so each and every
7:06
CSS property that we are providing right
7:08
here in this way after that we simply
7:12
create this table by using the table
7:18
constructor and we simply pass two
7:21
arguments here first of all the data
7:24
that we declared earlier on and then the
7:28
style the styles and then we
7:31
actually build the entire PDF document
7:35
by using the build method and here we
7:37
takes two arguments first of all the
7:40
title and then the
7:43
table that's all so this completes the
7:46
application it's very simple so let me
7:50
now delete this and rerun the script
7:54
once again run the script here you will
7:56
see on the left hand side result pdf has
7:59
been successfully generated if I open
8:02
this again you will see it will look
8:04
something like this first of all your
8:07
company name right
8:09
here then we have three columns and we
8:13
have these products we have subtotal
8:15
discount total we also have the price as
8:18
well
8:20
so depending upon your currency you can
8:23
change this currency as well like
8:26
this so in this way you can generate a
8:29
invoice data document in PDF format
8:33
using Python in report lab library so if
8:36
you need the full script the link is
8:38
given in the description of the video so
8:41
right in the CSS properties you can
8:43
manipulate
8:44
everything if let's suppose if you want
8:47
to change this background color to
8:49
something else let's suppose I want to
8:51
change it to yellow so once again if I
8:55
change this change this uh make this
9:00
modification and if I refresh now you
9:02
will see the color will be changed the
9:04
background color of the table has been
9:06
successfully changed so with this single
9:09
change you can see you can actually
9:11
change the entire result of your
9:14
application so the link is given in the
9:17
description you can get the full script
9:19
and thank you very much for watching
9:21
this video and also check out my website
9:23
freemediattools.com
9:25
uh which contains thousands of tools
#Accounting & Auditing
#Billing & Invoicing
#Business & Industrial
#Computers & Electronics