Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Extract attached file from encrypted PDF

I received an email with an attached pdf. This pdf was password-protected (encrypted). Atril thankfully can read those, but I didn't know how to view the file attached to the pdf. (Yes, I know, attached inside an attachment; I wasn't in control of the sender.)

Besides, who wants to use a graphical environment when a cli will do?

qpdf input.pdf output.pdf --decrypt --password='passphrasehere'
mkdir -p outdir
pdftk output.pdf unpack_files output outdir

Old research

My old solution involved pdftk and pdfdetach and for some reason I was failing to read the pdf correctly with pdftk.

pdftk inputfile.pdf input_pw 'passphrasehere' outputfile.pdf
pdfdetach -upw 'passphrasehere' -saveall inputfile.pdf

References

  1. How to Remove a Password from a PDF File in Linux
  2. Open a pdf with blank password with pdftk - Stack Overflow

Comments