How to print password protected pdf with cups from command line

cupspdfprinting

I have a *.pdf file that is password protected. I have the password and I can view the pdf with mupdf. However, printing with CUPS via lpr -P PRINTERNAME *.pdf does not work. All my printing is done via the command line and cups lpr command and I don’t want to change that. Is there a way to have CUPS print password protected pdfs?

Best Answer

Why not remove the password temporary and print the resulting unsecure pdf with lpr:

pdftk secure.pdf input_pw own output - | lpr

If you don't want that this command is listed in bash command history:

set +x history
<commands>
set -x history

OR

<whitespace><command>

OR use a script (adapted from here):

#!/bin/bash
unset password
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char; do
    [[ $char == $'\0' ]] && break
    prompt='*'
    password+="$char"
done
pdftk secure.pdf input_pw "$password" output - | lpr

Source for disabling bash history

Related Question