Class PDFEncryption
- java.lang.Object
-
- org.nuxeo.ecm.platform.pdf.PDFEncryption
-
public class PDFEncryption extends Object
Encrypt/Decrypt a PDF.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
Constructors Constructor Description PDFEncryption(Blob inBlob)Basic constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Blobencrypt(org.apache.pdfbox.pdmodel.encryption.AccessPermission inPerm)Encrypts the PDF with the new permissions (seeAccessPermission).BlobencryptReadOnly()Encrypts the PDF with readonly permission.BlobremoveEncryption()Removes all protection from the PDF, returns a copy of it.voidsetKeyLength(int keyLength)Set the lentgh of the key to be used for encryption.voidsetOriginalOwnerPwd(String originalOwnerPwd)Set the password to use when opening a protected PDF.voidsetOwnerPwd(String ownerPwd)Set the owner password to use when encrypting PDF.voidsetUserPwd(String userPwd)Set the user password to use when encrypting PDF.
-
-
-
Constructor Detail
-
PDFEncryption
public PDFEncryption(Blob inBlob)
Basic constructor.- Parameters:
inBlob- Input blob.
-
-
Method Detail
-
encryptReadOnly
public Blob 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.encryptReadOnlysets 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,originalOwnerPwdis used instead.setUserPwd(java.lang.String): The password for the user.
- Returns:
- A copy of the blob with the readonly permissions set.
-
encrypt
public Blob encrypt(org.apache.pdfbox.pdmodel.encryption.AccessPermission inPerm)
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,originalOwnerPwdis 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
public Blob 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,originalOwnerPwdis used instead.setUserPwd(java.lang.String): The password for the user.
-
setKeyLength
public void setKeyLength(int keyLength) throws NuxeoExceptionSet the lentgh of the key to be used for encryption.Possible values are 40 and 128. Default value is 128 if
keyLengthis <= 0.- Parameters:
keyLength- Length of the encryption key.- Throws:
NuxeoException
-
setOriginalOwnerPwd
public void setOriginalOwnerPwd(String originalOwnerPwd)
Set the password to use when opening a protected PDF. Must be called before encrypting the PDF.- Parameters:
originalOwnerPwd- Original owner password.
-
setOwnerPwd
public void setOwnerPwd(String ownerPwd)
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
public void setUserPwd(String userPwd)
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.
-
-