is it possible to check if pdf is password protected using ghostscript? what would be the command? I know you can strip pdf password using ghostscript, but all I want to do is just checking if PDF is password protected or security enabled.
checkuserpasswdPDF.sh
:
#!/bin/sh
GS=~/gs/bin/gs
output=`$GS -dBATCH -sNODISPLAY "$1" 2>&1`
gsexit=$?
if [ "$gsexit" == "0" ]; then
echo "Not user-password protected"
exit 0;
else
found=`echo "$output" |grep -o "This file requires a password"`
if [ -z "$found" ]; then
echo "Failed to invoke gs"
exit $gsexit
else
echo "Protected"
exit 0;
fi
fi
Checks for user-password protected PDFs: checkuserpasswdPDF.sh test.pdf
.
GS disregards owner-passwords (see this).
With pdftk
it is possible to detect a user password or owner password by just trying to do a dump_data
operation.
protected=0
pdftk "input.pdf" dump_data output /dev/null dont_ask || protected=1
The problem here is that you don't know what the password prevents: reading, extracting data, modifying...?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With