Java example to remove pdf password protection

broken image

Pdf.getSecurity().encrypt(openPassword, permissionPassword, flags, keySize) PdfEncryptionKeySize keySize = PdfEncryptionKeySize.Key_128_Bit ĮnumSet flags = EnumSet.of(PdfPermissionsFlags.Print, PdfPermissionsFlags.Fill_Fields) Pdf.loadFromFile('E:\\Files\\sample.pdf') Save the result file using PdfDocument.saveToFile () method.Encrypt the PDF file using PdfDocument.getSecurity().encrypt( openPassword, permissionPassword, permissions, PdfEncryptionKeySize keySize) method.Set open password, permission password, encryption key size and permissions.Load a sample PDF file using PdfDocument.loadFromFile() method.getSecurity().encrypt( openPassword, permissionPassword, permissions, PdfEncryptionKeySize keySize) method offered by Spire.PDF for Java allows you to set both open password and permission password to encrypt PDF files.

broken image

If a PDF file is secured with both types of passwords, it can be opened with either password. The former is set to open the PDF file, while the latter is set to restrict printing, contents copying, commenting, etc. There are two kinds of passwords for encrypting a PDF file - open password and permission password.

broken image