Is it possible to check if password is protected by pdf password with ghostscript?

Is it possible to check if password is protected by pdf password with ghostscript? What would be the team? I know that you can remove the pdf password using ghostscript, but all I want to do is just check if the PDF password is protected or the protection is enabled.

+6
ghostscript
source share
3 answers

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 password protected checkuserpasswdPDF.sh test.pdf : checkuserpasswdPDF.sh test.pdf .

GS ignores owner passwords (see this ).

+4
source share

Using pdftk you can determine the user password or owner password by simply performing the dump_data operation.

  protected=0 pdftk "input.pdf" dump_data output /dev/null dont_ask || protected=1 

The problem is that you do not know what prevents the password: reading, retrieving data, changing ...?

+2
source share

Using the bat file, you can make a small workaround by searching for "Encrypt" in pdf files. Its quiet speed for searching many files.

 Findstr /M /I "Encrypt" *.pdf 

This will return all the names of the files that have been protected (since "Encryption" will be written to the file as it is read)

Perhaps this is something someone can use. I use:
for /f %%a in ('Findstr /M /I "Encrypt" *.pdf') do move %%ac:\tempfiles\
move all protected pdfs to c: \ tempfiles. From there I use ghostscript to remove security and move it back to the original folder.

0
source share

All Articles