We often receive password encrypted pdfs on our mail from various places.
When saving these pdfs locally its a good idea to get rid of the password, so that we don't need to remember it later on.
On Ubuntu there are many simple ways to remove the password of a pdf files, each with its own pros and cons.
Lets take a look at them.
1. Print to PDF - the wrong way
Most tutorials out there would mention a simply and straight forward technique, that is to open the pdf in a viewer like Okular (on KDE) or Evince (on Gnome) and the use the Print to pdf option to print it again without any password.
This process creates a new pdf without any encryption effectively giving you a decrypted pdf.
However it creates a totally new pdf file that can sometimes be very different from the original in terms of appearance or structure.
For example a few images might go missing or some fonts might look weird. Even worse, sometimes the text might become un-selectable and the pdf content might be rasterized to image internally.
This happened recently when I was trying to print a pdf from Okular and output pdf had poor looking and unselectable text.
As an alternative I tried using Evince, which seemed to work better on this pdf but failed without another pdf where images went missing.
Looking for a solution, I tried to use a different pdf print driver from CUPS.
It prints pdfs to the /home/
$ sudo apt-get install printer-driver-cups-pdf
However even the CUPS pdf printer driver had similar problems, so I suspected that this isn't going to work.
2. pdftk - The correct way
It turned out that the correct way to remove the password is by modifying the original pdf and remove the password.
However it uses a command-line tool called pdftk.
First install the pdftk package.
$ sudo apt-get install pdftk
Now use the command as follows
$ pdftk /path/to/input.pdf input_pw <yourpassword> output out.pdf
The above command just removes the password and keeps the pdf the same as the original.
When you open both pdfs and compare them side by side, you would see that they are visually identical and the text layout and appearance is exactly the same.
So go ahead and try it.