Take the 2-minute tour ×

How to check pdf file is password protected or not in java.. I know of several tools/libraries that can do this but I want to know if this is possible with just program in java. Thanks in advance..

share|improve this question
you answered your own question. Use opensource libs like itext and write a java program to test. –  sudmong Feb 11 '13 at 6:25
I suppose some of these tools/libraries were written in pure java (while some others could be written in other languages, but it's not the matter of subject), weren't they? :) If so, why can't you write your own implementation of such password check? –  aga Feb 11 '13 at 6:30
As @aga pointed out, it obviously is possible to do that in Java. Thus, your question most likely misses some additional requirement you did not mention. Please explain your requirements. –  mkl Feb 11 '13 at 6:37
add comment

2 Answers

you can use PDFBox:


code example :

    document = PDDocument.load( yourPDFfile );

    if( document.isEncrypted() )
share|improve this answer
add comment

Using iText pdf API we can identify the password protected PDF.

Example :

    try {
            new PdfReader("C:\\Password_protected.pdf");            
        } catch (BadPasswordException e) {
            System.out.println("PDF is password protected..");
        } catch (Exception e) {
share|improve this answer
add comment

Your Answer


