Python 3 wkhtmltopdf & PDFKit Library Script to Convert HTML & CSS to PDF in Terminal
23 views
Jun 3, 2025
Buy the full source code of application here:
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you uh how
0:05
to basically convert your HTML files
0:07
with CSS into PDF inside Python using
0:11
this package which is PDF kit it's a
0:14
very popular package for converting your
0:16
HTML files into PDF using WK HTML to PDF
0:21
binary executable so you simply install
0:24
this module by executing this command
0:27
pip install PDF kit i have already
0:30
installed this module apart from that
0:32
you will also need to install WK HTML2
0:37
PDF it's a binary here which you do need
0:41
to install it's open source simply go to
0:43
the website and download this pre-ompile
0:46
binary after you download this so
0:50
basically it uh stores inside your C
0:54
drive so inside your program
0:57
files it basically
1:00
stores with this name wk html to pdf so
1:04
once you install this go to the bin
1:07
folder copy this path and just add this
1:11
into the environment variable so once
1:14
you add this go to the system
1:17
path i've already added this you can see
1:20
that click new and add this path i've
1:23
already added this path so once you add
1:25
the path you can directly use this PDF
1:28
kit library now just create a simple app
1:31
py file and then we simply import this
1:34
pdfkit library and after that there is a
1:38
single line here which contains this
1:41
from file function from
1:45
file and here we simply provide the
1:49
input HTML file that we need to convert
1:52
to PDF so then the output file name
1:56
let's suppose I say result PDF so simply
1:59
two lines of code we import the module
2:02
and then it contains this function here
2:04
we provide the input HTML file this is
2:07
your output PDF file so now once I run
2:11
this script here you will
2:18
see result.pdf PDF will be created and
2:23
this is your HTML right here this file
2:26
it contains a series of
2:30
headings a table as well so this is your
2:33
HTML file and this is your PDF
2:40
file so it successfully converted
2:42
everything and the nice thing is that
2:44
you can even import CSS as well so
2:46
custom CSS you can apply here h1 let's
2:49
suppose I say color should be red and
2:52
for the paragraph I say the color should
2:55
be green so we are applying some custom
2:58
CSS and once again if you do this you
3:01
will see it will apply that custom CSS
3:04
you can see
3:06
that so it's a very good library guys
3:09
PDF kit WK HTML to PDF in Python for
3:12
converting your HTML and CSS into PDF so
3:16
definitely use it and also Check out my
3:19
website freemediattools.com
3:21
uh which contains thousands of tools