Verify If a Word Document is Password Protected in Java

Verify If a Word Document is Password Protected in Java

2021-08-04 08:12:37 Written by  Koohji
Rate this item
(0 votes)

This article demonstrates how to verify if a Word document is password protected or not using Spire.Doc for Java.

The following image shows that the input Word document is protected with password:

Verify If a Word Document is Password Protected in Java

import com.spire.doc.Document;

public class DetectIfWordIsPasswordProtected {
    public static void main(String []args){
        //Detect if the Word document is password protected
        boolean isPasswordProtected = Document.isPassWordProtected("C:\\Users\\Administrator\\Desktop\\Sample.docx");
        if(isPasswordProtected)
        {
            System.out.println("The document is password protected.");
        }
        else
        {
            System.out.println("The document is not password protected.");
        }
    }
}

Output:

Verify If a Word Document is Password Protected in Java

Additional Info

  • tutorial_title:
Last modified on Tuesday, 31 August 2021 09:12