summarylogtreecommitdiffstats
path: root/decryptpdf
blob: da0978ae9f34e769f748d25ffe4d8818cdce1b86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

# AUTHOR:       (c) Glutanimate 2012 (http://askubuntu.com/users/81372/), namron 2017
# NAME:         PDFdecrypt 0.4
# DESCRIPTION:  A script to batch decrypt PDF files.
# DEPENDENCIES: qpdf kdialog libnotify-bin 
#               (install via sudo apt-get install qpdf libnotify-bin)
# LICENSE:      GNU GPL v3 (http://www.gnu.org/licenses/gpl.html)
# CHANGELOG:    0.3 - added notifications and basic error checking
#               0.2 - replaced obsolete gdialog with zenity
#               0.4 - replaced zenity with kdialog

password=`kdialog --password "PDF Password required"`

RET=$?

if [[ $RET = 0 ]]; then

  while [ $# -gt 0 ]; do
      ENCRYP=$1
      DECRYP=$(echo "$ENCRYP" | sed 's/\.\w*$/_decrypted.pdf/')
      qpdf --password=$password --decrypt "$ENCRYP" "$DECRYP"
      RET=$?
      if [[ $RET != 0 ]]; then
        ERR=1
      fi
      shift
  done

  if [[ $ERR = 1 ]]
    then
        notify-send -i application-pdf "PDFdecrypt" "All documents processed.There were some errors"
    else
        notify-send -i application-pdf "PDFdecrypt" "All documents decrypted."
  fi

else
  exit
fi