PDF Encryption & Decryption
This code example demonstrates how to modify metadata, make the PDF read-only, configure permissions, and change the document encryption password.
To begin, import an existing PDF document using the open method. This method can be utilized to open password-protected documents by specifying the password as the second parameter.
To set new metadata information, start by creating an empty Map and add key-value pairs for metadata, such as the author and keywords. Utilize the overrideMetadata
method to apply the new metadata to the PDF document.
Next, remove passwords and encryption using the removePasswordsAndEncryption
method, and configure the PDF to be read-only by setting a new password with the makePdfDocumentReadOnly
method.
Permissions for the PDF document are configured using an object named "permissions," which specifies whether certain actions, such as annotations, content extraction, form filling, and printing, are allowed or disallowed. Pass the permissions object to the setPermission
method.
Finally, change or set the document encryption password to "my-password," and save the modified PDF as "secured.pdf."