The encryption protects data and allows only authorized people to open the file. So, only those who have an encryption key (such as a password) can open and view a file.
If you want to check if a file is encrypted, use the getFileInfo() method that returns the file type and flag that indicates if the file is encrypted. The following code snippet shows how to check if a file is encrypted.
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.results.FileInfo;// ...
try(Viewerviewer=newViewer("encrypted.pdf")){FileInfofileInfo=viewer.getFileInfo();System.out.println("File type is: "+fileInfo.getFileType());System.out.println("File encrypted: "+fileInfo.isEncrypted());}
The following image shows a sample console output: