I am trying to password protect a large pdf collection, with one password per PDF file. I want to set a random and unique password for each PDF, and keep track of them as they are set.

I am looking for some automation, that can both set the random passwords, and store them in a csv or text file for future reference.

5 Answers 5


Use the PDF Toolkit, pdftk. It is open-source and runs on Windows as well as linux. You can add passwords, encryption, and modify permissions as follows from the examples here

Encrypt a PDF using 128-Bit Strength (the Default) and Withhold All Permissions (the Default)

pdftk mydoc.pdf output mydoc.128.pdf owner_pw foopass

Same as Above, Except a Password is Required to Open the PDF

pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz

Same as Above, Except Printing is Allowed (after the PDF is Open)

pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz allow printing

Then, in order to automate this for a large number of files, you'll need to create a batchfile (or powershell) to iterate. Since pdftk is all command line, this should not be hard. I wrote and tested the following batch-file. It works:


setlocal EnableDelayedExpansion
md out
for /f %%G in ('dir /b "*.pdf"') do (
    call:_pwgen passwd
    pdftk %%G output out/%%G user_pw !passwd!
    echo '%%G', '!passwd!' >> out/passwords.csv

goto :EOF

:_pwgen passwd
set _RNDLength=8
set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
set _Str=%_Alphanumeric%987654321
set passwd=%~1
if not "%_Str:~18%"=="" set _Str=%_Str:~9%& set /A _Len+=9& GOTO :_LenLoop
set _tmp=%_Str:~9,1%
set /A _Len=_Len+_tmp
set _count=0
set _RndAlphaNum=
set /a _count+=1
set _RND=%Random%
set /A _RND=_RND%%%_Len%
set _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
if !_count! lss %_RNDLength% goto _loop
set passwd=!_RndAlphaNum!
endlocal&set %~1=%passwd%

Thanks to other discussion here on how to generate random passwords in a batch file.


If you work at a business where the PDF information is private, uploading to anywhere is not wise. You would be giving this info to that company.

Since a person would likely be trying to encrypt the info for privacy, it's a catch 22. I would recommend doing it yourself with software you can install locally or use cmdline options as well.


How about using a Tool tu Protect your File, ALL's FREE; try, maybe can help you

1.PDFProtect DFProtect locks or password your pdf files online without you installing any software on your pc.It requires you to upload your pdf files and download it back to lock your pdf files. http://www.pdfprotect.net/

2.Weeny Free PDF Cutter:You can use weeny free pdf cutter to cut and split PDF files into multiple files.Apart from this feature,you can also lock or password your pdf files. http://www.weenysoft.com/free-pdf-cutter.html

3.PrimoPDF:A Pdf software that you use to convert and word document into pdf and then password the converted pdf files.To password protect your document,just go to option button and create password under pdf security. http://download.cnet.com/PrimoPDF/3000-18497_4-10264577.html

4.Doro PDF Writer:When it comes to additional options like password protection and all, you need a tool like Doro PDF Writer. It lets you create PDF files from the “print” dialog box of Windows, and encrypt it with a password, prevent functions like copy/paste, printing of the file and more. http://thesz.diecru.eu/content/doro.php


You may try PDF Password Security, it helps protect mass pdf files easily. However, it can only let you protect multiple PDFs with the same open password or restrictions.

I failed to find out an app that can set random password in batch. And once the PDF is protected by open password, users cannot even get access the PDF, how can you tell user the link. So I don't think any software can make it.


The best way is to give each file a file name based password.

Solution1 (completely online)

  1. go to http://md5encryption.com/, paste your pdf file name there and copy the hash word.
  2. go to http://www.pdfprotect.net/, paste your hash string there, upload your file and get it protected.

Solution 2 (partially online)

  1. go to http://md5encryption.com/, paste your pdf file name there and copy the hash word.
  2. Get some software like Primo PDF to set password.

This way you can link and tell him ,where he can find password to that file.

Hope this helps.

  • An md5-hash of the filename is not quite random and defeats the purpose of having different passwords for different files. Even if the algorithm is kept secret, knowing one password makes finding how it is deduced trivial and thus compromises the security of the others. May 25, 2012 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.