I have some n number of pdf files which are SECURED( i.e not password secured, but owner secured). I was able to decrypt single pdf at a time using _ "qpdf --decrypt Input.pdf Output.pdf" from Cmd Promt in Windows. can you help me to do the same with multiple pdf's using batch file or from cmd prompt.
5 Answers
If you just want to run the command from the shell (cmd.exe), you can do something like this from the directory containing the PDFs:
for %a in ("*.pdf") do "c:\Programs\qpdf\bin\qpdf.exe" --decrypt "%a" "%~dpna.decrypted.pdf"

- 263
- 3
- 11
@echo off
setlocal enableextensions disabledelayedexpansion
if not exist output\ md output
for %%a in (*.pdf) do qpdf --decrypt "%%~fa" "output\%%~nxa"
Create an output folder under current directory. Then for each pdf in current folder call qpdf to decrypt, passing as argument the full path of the input file (%%~fa
) and the output file, that is, the output folder followed by the name and extension of the file being processed (%%~nxa
)

- 69,615
- 8
- 84
- 126
-
Thank you there @MC ND it perfectly fine.. thanks again for the help. – Santosh Raj Jul 21 '14 at 13:53
#!/bin/bash
# unprotect multiple pdf files in a directory with qpdf 10Jan20
# run the script from the same directory as the files
if [ -d output ];
then
echo "output directory exists"
else
mkdir output
fi
yourfilenames=`ls *.pdf`
#echo yourfilenames
for eachfile in $yourfilenames
do
echo $eachfile
qpdf --decrypt $eachfile output/$eachfile
done

- 41
- 1
-
Question was "from Cmd Promt in *Windows*". This looks like a Unix solution to me. – geogan Feb 01 '23 at 12:40
Try this: Place all the pdfs in one folder and navigate with cmd prompt to that folder. Execute the following commands:
mkdir output
qpdf --decrypt *.pdf output/*.pdf

- 419
- 1
- 4
- 16
-
1Hi there i am getting the following error "qpdf: unknown argument chap3.pdf Usage: qpdf [options] infile outfil For detailed help, run qpdf --help" i have some 5 pdf named chap1 - 5.. What could be the problem.. and thanks for your answer @Casper – Santosh Raj Jul 21 '14 at 13:02
-
Ah that's my fault. It is 'qpdf --decrypt *.pdf output' and if that doesn't work try 'qpdf --decrypt *.pdf *.decrypted.pdf' – Casper Jul 21 '14 at 13:13
-
even after trying with both commands it shows again the same error.."qpdf: unknown argument chap3.pdf Usage: qpdf [options] infile outfile For detailed help, run qpdf --help" – Santosh Raj Jul 21 '14 at 13:18
-
Ahh lousy application implementation.. try 'for /r %i in (\*) do qpdf --decrypt %i output/' and if not working 'for /r %i in (\*) do qpdf --decrypt %i output/%i' – Casper Jul 21 '14 at 13:24
-
as i used 'for /r %i in (*) do qpdf --decrypt %i output/' it throwing an error saying 'open output/: Permission denied' and when i run 'for /r %i in (*) do qpdf --decrypt %i output/%i' it again throws error saying 'open output/F:\***\pd\chap1.pdf: Invalid argument' – Santosh Raj Jul 21 '14 at 13:31
-
Please bear with me, I don't have a Windows machine right now ;) Try: 'for /r %i in (\*) do if %i != "output" qpdf --decrypt %i output' – Casper Jul 21 '14 at 13:36
Just use the following command line statement:
for %a in ("*.pdf") do qpdf --decrypt "%a" "%~dpna.decrypted.pdf"
with an elevated command prompt from outside the usual qpdf folder BIN folder.
Before that put copies of all your locked PDF files inside the BIN folder and run the command line statement.
You will get unlocked files with the "original filename" + ".decrypted.pdf" extension. SEARCH for "decrypted" in file manager while inside the BIN folder and copy paste all those file into a known location. You can use "BULK RENAME Utility" to intelligently rename the set of PDF files or remove the "decrypted" part addition to the new file .

- 5,743
- 3
- 32
- 44

- 11