Remove passwords from your Airtel post-paid bills, HDFC premium receipts, Bank statements & similar PDF documents

Shashank Srivastava
5 min readMar 4, 2020

This simple shell script written by me will let you create password-less copies of your password-protected PDF documents.

Photo by Shane Avery on Unsplash

Introduction

Most of the bank & investment statements are password-protected so you have to enter a password every time you need to open the document. While it is great for security purposes, entering the password becomes really irritating when you have to do it again & again & again.

The worst part is, you may even forget the password & hence you simply can’t access those documents.

To save some time, I wrote a shell script called RemovePDFPassword that decrypts your secure PDF documents & copies them to a different directory where you can easily access them without entering the password. It works on a given directory, so it can very quickly decrypt the entire directory before you even get the chance to blink your eyes! The script works well when you have placed all those statements that have a common password inside a particular folder. For example, you can keep all your Axis Bank statements in a folder & RemovePDFPassword will quickly decrypt all the files inside it & copy them to a different location. Your original documents remain untouched.

This utility comes in 2 flavors. One (RemovePDFPassword.sh) has the password hard-coded for convenience, which means the script won't ask for a password while executing. This is ideal for situations where you have a large number of files inside a single folder. The second version (RemovePDFPassword-input.sh) prompts for the password, so it is ideal for the cases where you have multiple directories & you don't want to edit the script every time.

My script works on Mac, Ubuntu & RedHat based systems. It doesn’t touch the original files — your original files are always safe.

How To Use?

  • Clone/download the script from my GitHub repo.
  • Make it executable.
  • After this, change line #77 & replace the word PASSWORD with your password. This is optional.
for f in *; do [[ -d "$f" ]] || qpdf --password=PASSWORD --decrypt "$f" "${HOME}/Decrypted_PDF_Documents/$f-UNSECURED.pdf"; done

The above step is only applicable for RemovePDFPassword.sh script. RemovePDFPassword-input.sh script doesn’t have a hard-coded password.

  • Execute the script as…
./removePasswordPDF.sh

It will prompt you to enter the path of your password-protected PDF files.

Script in action

On Ubuntu : —

root@development-server /h/s/Shell Scripts# ./removePasswordPDF.sh 
Detecting OS of your machine...

Your OS is : - Ubuntu.

Checking QPDF insallation...

This script requires a package called QPDF in order to decrypt your PDF files 8-) Do you want to install it? Its a one time process only. Press y to install or n to cancel.
n
You chose not to install QPDF :-( I will exit now!!!

If you choose not to install the qpdf package, then the script will exit (as you can see above). This package is needed for the script to run. If you specify an invalid path or a path with no PDF files, then the script will not do anything.

root@development-server /h/s/Shell Scripts# ./removePasswordPDF.sh 
Detecting OS of your machine...

Your OS is : - Ubuntu.

Checking QPDF insallation...

This script requires a package called QPDF in order to decrypt your PDF files 8-) Do you want to install it? Its a one time process only. Press y to install or n to cancel.
y
You chose to install QPDF. Installing it for your Ubuntu now :-)
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libqpdf17
The following NEW packages will be installed:
libqpdf17 qpdf
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 509 kB of archives.
After this operation, 1,400 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu zesty/main amd64 libqpdf17 amd64 6.0.0-2 [300 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu zesty/main amd64 qpdf amd64 6.0.0-2 [210 kB]
Fetched 509 kB in 3s (161 kB/s)
Selecting previously unselected package libqpdf17:amd64.
(Reading database ... 201002 files and directories currently installed.)
Preparing to unpack .../libqpdf17_6.0.0-2_amd64.deb ...
Unpacking libqpdf17:amd64 (6.0.0-2) ...
Selecting previously unselected package qpdf.
Preparing to unpack .../qpdf_6.0.0-2_amd64.deb ...
Unpacking qpdf (6.0.0-2) ...
Setting up libqpdf17:amd64 (6.0.0-2) ...
Processing triggers for libc-bin (2.24-9ubuntu2.2) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up qpdf (6.0.0-2) ...
This script will decrypt all the encrypted PDF documents in the provided directory, given they all have the same password.
Enter the full path where your encrypted PDF documents are stored.../home/shashank/encrypted_PDF
You provided /home/shashank/encrypted_PDF as the path. Performing magic there! ;-) But before that, lets see if this directory contains any PDF files or not.
ls: cannot access '/home/shashank/encrypted_PDF': No such file or directory
./removePasswordPDF.sh: line 53: cd: /home/shashank/encrypted_PDF: No such file or directory
Looks like /home/shashank/encrypted_PDF is empty & does not contain any file at all. Exiting now...

On Mac — with valid PDF files.

admin@shashank-mbp ~/D/Shell Scripts> ./removePasswordPDF.sh
Detecting OS of your machine...

Your OS is : - Mac OS X.

Checking QPDF insallation...

/usr/local/bin/qpdf
QPDF already installed! Lets get started :-)
This script will decrypt all the encrypted PDF documents in the provided directory, given they all have the same password.
Enter the full path where your encrypted PDF documents are stored.../Users/admin/Desktop/Secured_PDF/
You provided /Users/admin/Desktop/Secured_PDF/ as the path. Performing magic there! ;-) But before that, lets see if this directory contains any PDF files or not.
Number of pdf files: 5
Your original files won't be touched. New decrypted files will be created in directory : - /Users/admin/Decrypted_PDF_Documents.
Directory /Users/admin/Decrypted_PDF_Documents already exists, hence not creating it!
Success!! You can now navigate to /Users/admin/Decrypted_PDF_Documents directory to access your PDF documents without having to enter passwords :-)

I hope this post was informative & useful. Do let me know if you found this script interesting.

--

--

Shashank Srivastava

DevSecOps Architect @Virtualness. Music/Book/Photography/Fitness lover & Blogger.