How to Encrypt a Password Around and Merge Multiple PDFs in Ubuntu
For some reason, this is way harder than it should be. I thought I would be able to find a simple ‘pdf stitcher’ software in the Software Centre and just put them in there, arrange them and then export to PDF – with a password. I think this used to be possible with PDF Sam but anyway. This tutorial will hopefully be a long term and reliable way that we can do this in a pinch from any machine.
This is all terminal based so get ready to pump up your terminal skills.
1. Stick PDFs in a Dedicated Folder
Assemble into one directory all the PDFs you plan to stitch together and wrap up with a password. I think the command will only work if they are in one place so this step is important.
2. Install PDFTK
sudo apt install pdftk… I think… but you might need some other package these days… remind me in comments if this is wrong 🙂
3. Go to your PDF directory
Using the CD (change directory) command, navigate to the directory you made in step 1.
4. Run the Command for One Page Only.
This is the basic format for PDFTk showing one file being output with a new name and a password
pdftk [mydoc_old].pdf output [mydoc_new].pdf user_pw [awesomepasswd]
In this case you”ll swap out the filenames accordingly.
*Special note! do not put the square brackets in there. those are just to show you what needs to be swapped out. I actually did this and wasted a lot of time (lol)
Also, take note of this, you ‘might’ get a warning that the PDF has a user password and you can’t do these tasks because you don’t know the owner password. It seems banks do this on their bank statements, which is funny, because they don’t supply a secure way to send banking documents to them and ask me to email…
Error will look like this if you need to work around it:
has set an owner password (which is not required to handle this PDF).
You did not supply this password. Please respect any copyright.
I found a nice work around to stick it to these bankers which is to use the Ubuntu ‘print’ (ie. printing to your printer) and then change from your printer to ‘print to file’. Side note: If you didn’t know about this built in and super easy PDF feature and you only need to do one PDF at a time and no encryption, this is the way to do it.
The output PDF from this method seems to strip away any of the ‘owner password’ annyoyances. Hint: this is also a good time to rename your individual pdfs to a number in the order you want them to appear in the final merged PDF. I do 001, 002, 003 during this phase making the next section way, way easier.
5. Run the Command for Merging Multiple PDFs
The process is the same as above, but now that you have your folder full of 001, 002, 003 numbered files, here is what you do:
pdftk .pdf .pdf [003.pdf] output [mydoc_new].pdf user_pw [awesomepasswd]
Once you hit ‘enter’ a new file will appear in the same directory with name ‘mydoc_new.pdf’ and will have 001, 002, 003 in it and be locked behind the password ‘awesomepasswd’.
Pretty handy especially when you have to deal with ‘owner passwords’ in the PDF.
Hope this helps!