Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unlock protected pdf files

I need to process a large number of protected pdf files and edit them using a java program, but i don't have the passwords for these files. Is there any way to unlock this files with a batch?

I would like a windows command like tool or a java open source api. What is the best solution ?

like image 739
brianbro Avatar asked Jan 05 '12 20:01

brianbro


3 Answers

are these pdf files asking for passwords to be opened, or protection consist in restrictions about copy, printing, modify, text extraction and so on?

if this is your case, you can try with

qpdf

  • http://qpdf.sourceforge.net/

usage:

qpdf --decrypt file.pdf unlocked.pdf

and can be used in a batch operation en masse, in this way

for f in *.pdf ; do qpdf --decrypt $f ${f%%.pdf}unlocked.pdf; done
like image 143
Dingo Avatar answered Nov 05 '22 09:11

Dingo


For decryption, you can use PDFBox, see my answer here : https://stackoverflow.com/a/9976481/535203

I give a sample code to decrypt a PDF given its password.

There is also a binary to do that with PDFBox, check the usage here.

like image 38
Anthony O. Avatar answered Nov 05 '22 10:11

Anthony O.


You can also do it using iText library.

Here is a sample code :

        PdfReader.unethicalreading = true;
        PdfReader reader = new PdfReader(inputFile);
        PdfEncryptor.encrypt(reader, new FileOutputStream(outputFile), null,
              null, PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY
                  | PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_FILL_IN
                  | PdfWriter.ALLOW_MODIFY_ANNOTATIONS | PdfWriter.ALLOW_MODIFY_CONTENTS
                  | PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_SCREENREADERS, false);

P.S. : use unethicalreading flag on your own risk.

like image 1
Himanshu Tyagi Avatar answered Nov 05 '22 09:11

Himanshu Tyagi