Python 3 img2pdf & PyAutoGUI Script to Automate & Take Screenshot of Desktop & Export to PDF in CMD
0 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-img2pdf-pyautogui-script-to-automate-take-screenshot-of-desktop-export-to-pdf-in-cmd/
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you a Python
0:04
script which will automatically take the
0:06
screenshot of your screen and also
0:08
convert that screenshot into PDF file as
0:11
well so both the things it will do at
0:14
the same time let me just show run this
0:16
Python script so as soon as I execute
0:19
this Python script just see on the left
0:21
hand side it will take the screenshot
0:24
and then it will also convert that
0:26
screenshot into PDF file as well so as
0:29
you can see this is actually a PNG image
0:32
screenshot and then it also converts
0:35
that into a PDF file as well so uh for
0:38
this we are using two Python libraries
0:40
first of all we are using PI autoguy
0:43
which is a automation
0:45
library inside Python very famous which
0:49
is py auto GUI this is actually the name
0:53
of the package
0:55
simply install this by executing this
0:58
command so with the help of this library
1:00
you can automate anything inside Python
1:03
and then for converting that image to
1:05
PDF we are using this package here which
1:07
is image to PDF it's a very handy Python
1:11
package for converting images into PDF
1:14
so these two libraries we are using i
1:16
have given all the source code in the
1:18
description of the video so now let me
1:20
show you from scratch how
1:25
I made this application so I will just
1:28
write this source code step by step and
1:31
then show you how basically how just
1:34
create a simple app py file and uh first
1:37
of all you need to import the required
1:39
packages which is your pi autogy and
1:42
then we also need to import image to pdf
1:46
and then here we need to
1:48
specify the screenshot for taking the
1:51
screenshot we use this method pi autogy
1:54
it contains this screenshot method it
1:56
will automatically take the screenshot
1:58
of your screen and then we need to save
2:01
the screenshot and the path here so here
2:04
we'll be saving it right in the same
2:07
directory screenshot.png this will be
2:09
the
2:10
name after saving the screenshot now we
2:14
just need to save that using the save
2:17
method add that path screenshot
2:21
path after that we just need to convert
2:24
that screenshot into PDF file as well so
2:27
first for that we need to first of all
2:30
open
2:32
this screenshot in read mode read binary
2:36
mode and then for converting it to PDF
2:40
file we open the PDF output PDF into
2:45
write binary
2:48
mode and
2:50
then we invoke this PDF
2:54
file we use the write method and then we
2:57
use this package image to PDF and here
3:00
we use this convert method to
3:04
actually convert this image file that we
3:08
have which is image
3:10
file and uh this will actually convert
3:13
your image to PDF and then we can close
3:16
the connection here by invoking the
3:19
close method and also close
3:21
the So this completes your script uh
3:24
very simple script first of all it uses
3:27
this pi autogy package to automatically
3:29
take the screenshot save it as a image
3:31
file and then after saving it as a image
3:34
file then we open this image file in
3:36
read binary mode and convert this image
3:39
file into PDF by using this package
3:41
image to
3:43
PDF so here at the top here we can see
3:46
we are importing this so now let me just
3:50
execute this script here you will see on
3:52
the left hand side it will create these
3:54
two files first of all the image file
3:56
and then the PDF file
3:59
so in this easy way you can build out
4:03
this application right in the terminal
4:04
itself uh thank you very much for
4:07
watching this video and also check out
4:09
my website freemediatools.com
4:12
uh which contains thousands of tools