A PDF file that contains sensitive information and are shared via email are usually protected with a long and secure password, so only the indended user can open the file. That's alright, at least for the normal user, however for those advanced users that know how to use the command line of Windows, the terminal of linux, that's pretty tedious. Although there are a lot of online tools that allow you to remove the password of a PDF without effort, if you are a developer that aims to create an application with a feature that removes the password of a PDF (knowing the password of the file of course), you will need to use a third party tool/library to achieve this quickly.
QPDF is one of those tools that makes everything related to a PDF pretty easy to achieve through the CLI. QPDF is a command-line program that does structural, content-preserving transformations on PDF files. It could have been called something like pdf-to-pdf. It also provides many useful capabilities to developers of PDF-producing software or for people who just want to look at the innards of a PDF file to learn more about how they work.
Although in this short article, we will use it for a very simple thing, it's worth to mention that this is a widely needed feature for many people. We will explain you shortly how to create an unprotected copy (without password) of an encrypted PDF (password protected).
This tutorial assumes that YOU DO KNOW THE PASSWORD TO UNLOCK THE PDF. We are not explaining a way to hack/remove the protection of a PDF file.
We assume that you already downloaded and installed QPDF for your system (windows, linux etc). The command to create an unencrypted copy a file is the following one:
qpdf --decrypt --password=12345 encrypted_file.pdf output_file.pdf
You will use the
--decrypt argument basically to achieve your goal. This function removes any encryption on the file, however, a password must be supplied if the file is password protected. You will provide this password with the
--password argument and finally provide the input file (the PDF with the password protection) and the output file (the PDF that will be generated without protection).
Happy coding !
Become a more social person