Class PDFEncryption
Notice that encryption is not only about pure encryption, it is also about setting the available features on the pdf:
can print, copy, modify, ... (see PDFBox AccessPermission
).
To use this class and its encrypt()/removeEncryption() methods you must always use the appropriate setters first, to set the misc info (original owner password so an encrypted PDF can be handled, encryption key length, ...).
- Since:
- 8.10
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionencrypt
(org.apache.pdfbox.pdmodel.encryption.AccessPermission inPerm) Encrypts the PDF with the new permissions (seeAccessPermission
).Encrypts the PDF with readonly permission.Removes all protection from the PDF, returns a copy of it.void
setKeyLength
(int keyLength) Set the lentgh of the key to be used for encryption.void
setOriginalOwnerPwd
(String originalOwnerPwd) Set the password to use when opening a protected PDF.void
setOwnerPwd
(String ownerPwd) Set the owner password to use when encrypting PDF.void
setUserPwd
(String userPwd) Set the user password to use when encrypting PDF.
-
Constructor Details
-
PDFEncryption
Basic constructor.- Parameters:
inBlob
- Input blob.
-
-
Method Details
-
encryptReadOnly
Encrypts the PDF with readonly permission.WARNING: If you are familiar with PDFBox
AccessPermission
, notice our encryptReadOnly() method is not the same asAccessPermission.setReadOnly()
. The latter just makes sure the code cannot call other setter later on.encryptReadOnly
sets the following permissions on the document:- Can print: True
- Can Modify: False
- Can Extract Content: True
- Can Add/Modify annotations: False
- Can Fill Forms: False
- Can Extract Info for Accessibility: True
- Can Assemble: False
- Can print degraded: True
IMPORTANT
It is required that the following setters are called before:setOriginalOwnerPwd(java.lang.String)
: Only if the original PDF already is encrypted. This password allows to open it for modification.setKeyLength(int)
: To set the length of the key.setOwnerPwd(java.lang.String)
: The password for the owner. If not called,originalOwnerPwd
is used instead.setUserPwd(java.lang.String)
: The password for the user.
- Returns:
- A copy of the blob with the readonly permissions set.
-
encrypt
Encrypts the PDF with the new permissions (seeAccessPermission
).IMPORTANT
It is required that the following setters are called before:setOriginalOwnerPwd(java.lang.String)
: Only if the original PDF already is encrypted. This password allows to open it for modification.setKeyLength(int)
: To set the length of the key.setOwnerPwd(java.lang.String)
: The password for the owner. If not called,originalOwnerPwd
is used instead.setUserPwd(java.lang.String)
: The password for the user.
- Parameters:
inPerm
- Input permissions.- Returns:
- A copy of the blob with the new permissions set.
-
removeEncryption
Removes all protection from the PDF, returns a copy of it. If the PDF was not encrypted, just returns a copy of it with no changes.IMPORTANT
If the PDF is encrypted, it is required forsetOriginalOwnerPwd(java.lang.String)
to be called before toremoveEncryption
.setOriginalOwnerPwd(java.lang.String)
: Only if the original PDF already is encrypted. This password allows to open it for modification.setKeyLength(int)
: To set the length of the key.setOwnerPwd(java.lang.String)
: The password for the owner. If not called,originalOwnerPwd
is used instead.setUserPwd(java.lang.String)
: The password for the user.
-
setKeyLength
Set the lentgh of the key to be used for encryption.Possible values are 40 and 128. Default value is 128 if
keyLength
is <= 0.- Parameters:
keyLength
- Length of the encryption key.- Throws:
NuxeoException
-
setOriginalOwnerPwd
Set the password to use when opening a protected PDF. Must be called before encrypting the PDF.- Parameters:
originalOwnerPwd
- Original owner password.
-
setOwnerPwd
Set the owner password to use when encrypting PDF. Must be called before encrypting the PDF.Owners can do whatever they want to the PDF (modify, change protection, ...).
- Parameters:
ownerPwd
- Owner password.
-
setUserPwd
Set the user password to use when encrypting PDF. Must be called before encrypting the PDF.Users can have less rights than owners (for example, not being able to remove protection).
- Parameters:
userPwd
- User password.
-