Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decrypt multiple pdf files using qpdf?

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.

like image 825
Santosh Raj Avatar asked Jul 21 '14 12:07

Santosh Raj


3 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"

like image 172
arjan Avatar answered Oct 23 '22 14:10

arjan


@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)

like image 33
MC ND Avatar answered Oct 23 '22 14:10

MC ND


#!/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
like image 25
m173 Avatar answered Oct 23 '22 13:10

m173