Python 3 PyAutoGUI Script to Automate & Take Screenshot of Desktop & Export to PDF Using Pillow
23 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-pyautogui-script-to-automate-take-screenshot-of-desktop-export-to-pdf-using-pillow/
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
take the screenshot of your uh desktop
0:07
screen and uh also save it as a PDF file
0:10
as well So for this we are using this
0:13
Python script here Uh if I just show you
0:16
if I execute the script here you will
0:18
see it will take the screenshot and uh
0:21
also it will convert this into PDF file
0:23
as well So it taken the screenshot So
0:27
this is actually you will see it taken
0:30
the screen screenshot PNG file and then
0:34
it also converted this into PDF file as
0:37
well So you will see it created two
0:38
files this script as soon as I executed
0:41
this First of all it taken the
0:44
screenshot This is your PNG file and
0:48
then it also converted into PDF file as
0:51
well So these two files is it created So
0:55
for automating this process we are using
0:58
a library called as PI auto GUI This is
1:01
actually a very famous library which
1:04
lets you control your
1:08
uh your mouse and keyboard or other
1:12
automation task you can do inside your
1:16
application So this is actually a Python
1:18
library Simply install this pip install
1:22
pi autogy I have already installed it
1:25
and also we are using the pillow library
1:28
as well which is a image processing
1:31
library We also need this library as
1:34
well So simply install this as well pip
1:36
install pillow I have given all the
1:39
source code in the description of this
1:41
video So now let me show you how to
1:45
uh write this code step by step
1:52
So so just create a simple app py file
1:56
and now let me show you from scratch So
1:59
first of all we need to require the
2:01
necessary packages So we simply say
2:03
import pi autogui and then from the
2:08
pillow library pil we need to import the
2:10
image class After importing the modules
2:14
we just need to specify where we need
2:17
to save the screenshot So here we will
2:20
be using this pi autogy method which
2:25
contains the screenshot method So it
2:27
will automatically take the screenshot
2:29
once you execute the python script using
2:31
this method After that here we need to
2:35
specify at which path we need to save
2:39
the image file So here we will be
2:42
specifying we need to save it right in
2:45
the current directory
2:48
screenshot.png and then after that uh we
2:53
will invoke this save method which will
2:58
save the screenshot at that particular
3:00
location and we pass the path here
3:02
screenshot path So what now if I execute
3:05
the script now it will take the
3:07
screenshot and then it will save this
3:11
screenshot.png file you will see
3:14
that so as soon as I execute this it
3:18
takes the screenshot automatically by
3:20
using this pi autogy screenshot method
3:23
and then it saves at that location Uh
3:26
but we also need to convert this image
3:29
file to PDF file as well So for
3:32
converting that we now need to use the
3:35
pillow library We need to open this
3:39
image and then we need to convert this
3:44
into first of
3:48
all convert this into RGB red green blue
3:53
alpha and then here we need to make the
3:57
output path here which will be the out
4:00
uh output PDF file and then we simply
4:04
need to say open image
4:07
save
4:11
output path That's all That's all that
4:15
we need to do Once we get the image file
4:19
then we simply open the image by using
4:21
the pillow image class Then we convert
4:24
this into RGB Then we save this as a PDF
4:29
file So now what happens if
4:31
I again rerun the script here it first
4:36
of all take the screenshot and then it
4:39
converts it into PDF So in this easy way
4:42
you can use this Python script to
4:44
automate taking the screenshot and also
4:48
converting it to PDF file as well
4:51
So so this is a very useful library pi
4:54
autogy which is a automation library for
4:58
controlling mouse keyboard anything you
5:00
can control inside Python And thank you
5:03
very much for watching this video and
5:05
also check out my website
5:06
freemediattools.com
5:08
uh which contains thousands of tools