Package com.itextpdf.kernel.pdf
Class PdfEncryptor
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfEncryptor
-
public final class PdfEncryptor extends java.lang.Object
This class takes any PDF and returns exactly the same but encrypted. All the content, links, outlines, etc, are kept. It is also possible to change the info dictionary.
-
-
Field Summary
Fields Modifier and Type Field Description private static IBouncyCastleFactory
BOUNCY_CASTLE_FACTORY
private IMetaInfo
metaInfo
private EncryptionProperties
properties
-
Constructor Summary
Constructors Constructor Description PdfEncryptor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
encrypt(PdfReader reader, java.io.OutputStream os)
Entry point to encrypt a PDF document.static void
encrypt(PdfReader reader, java.io.OutputStream os, EncryptionProperties properties)
Entry point to encrypt a PDF document.static void
encrypt(PdfReader reader, java.io.OutputStream os, EncryptionProperties properties, java.util.Map<java.lang.String,java.lang.String> newInfo)
Entry point to encrypt a PDF document.void
encrypt(PdfReader reader, java.io.OutputStream os, java.util.Map<java.lang.String,java.lang.String> newInfo)
Entry point to encrypt a PDF document.static byte[]
getContent(IRecipientInformation recipientInfo, java.security.PrivateKey certificateKey, java.lang.String certificateKeyProvider)
Gets the content from a recipient.static java.lang.String
getPermissionsVerbose(int permissions)
Give you a verbose analysis of the permissions.static boolean
isAssemblyAllowed(int permissions)
Tells you if document assembly is allowed.static boolean
isCopyAllowed(int permissions)
Tells you if copying is allowed.static boolean
isDegradedPrintingAllowed(int permissions)
Tells you if degraded printing is allowed.static boolean
isFillInAllowed(int permissions)
Tells you if filling in fields is allowed.static boolean
isModifyAnnotationsAllowed(int permissions)
Tells you if modifying annotations is allowed.static boolean
isModifyContentsAllowed(int permissions)
Tells you if modifying content is allowed.static boolean
isPrintingAllowed(int permissions)
Tells you if printing is allowed.static boolean
isScreenReadersAllowed(int permissions)
Tells you if repurposing for screenreaders is allowed.PdfEncryptor
setEncryptionProperties(EncryptionProperties properties)
Sets theEncryptionProperties
PdfEncryptor
setEventCountingMetaInfo(IMetaInfo metaInfo)
Sets theIMetaInfo
that will be used duringPdfDocument
creation.
-
-
-
Field Detail
-
BOUNCY_CASTLE_FACTORY
private static final IBouncyCastleFactory BOUNCY_CASTLE_FACTORY
-
metaInfo
private IMetaInfo metaInfo
-
properties
private EncryptionProperties properties
-
-
Method Detail
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, EncryptionProperties properties, java.util.Map<java.lang.String,java.lang.String> newInfo)
Entry point to encrypt a PDF document.- Parameters:
reader
- the read PDFos
- the output destinationproperties
- encryption properties. SeeEncryptionProperties
.newInfo
- an optionalString
map to add or change the info dictionary. Entries withnull
values delete the key in the original info dictionary
-
encrypt
public static void encrypt(PdfReader reader, java.io.OutputStream os, EncryptionProperties properties)
Entry point to encrypt a PDF document.- Parameters:
reader
- the read PDFos
- the output destinationproperties
- encryption properties. SeeEncryptionProperties
.
-
getPermissionsVerbose
public static java.lang.String getPermissionsVerbose(int permissions)
Give you a verbose analysis of the permissions.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- a String that explains the meaning of the permissions value
-
isPrintingAllowed
public static boolean isPrintingAllowed(int permissions)
Tells you if printing is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if printing is allowed
-
isModifyContentsAllowed
public static boolean isModifyContentsAllowed(int permissions)
Tells you if modifying content is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if modifying content is allowed
-
isCopyAllowed
public static boolean isCopyAllowed(int permissions)
Tells you if copying is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if copying is allowed
-
isModifyAnnotationsAllowed
public static boolean isModifyAnnotationsAllowed(int permissions)
Tells you if modifying annotations is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if modifying annotations is allowed
-
isFillInAllowed
public static boolean isFillInAllowed(int permissions)
Tells you if filling in fields is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if filling in fields is allowed
-
isScreenReadersAllowed
public static boolean isScreenReadersAllowed(int permissions)
Tells you if repurposing for screenreaders is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if repurposing for screenreaders is allowed
-
isAssemblyAllowed
public static boolean isAssemblyAllowed(int permissions)
Tells you if document assembly is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if document assembly is allowed
-
isDegradedPrintingAllowed
public static boolean isDegradedPrintingAllowed(int permissions)
Tells you if degraded printing is allowed.- Parameters:
permissions
- the permissions value of a PDF file- Returns:
- true if degraded printing is allowed
-
getContent
public static byte[] getContent(IRecipientInformation recipientInfo, java.security.PrivateKey certificateKey, java.lang.String certificateKeyProvider) throws AbstractCMSException
Gets the content from a recipient.- Parameters:
recipientInfo
- recipient informationcertificateKey
- private certificate keycertificateKeyProvider
- the name of the certificate key provider- Returns:
- content from a recipient info
- Throws:
AbstractCMSException
- if the content cannot be recovered.
-
setEventCountingMetaInfo
public PdfEncryptor setEventCountingMetaInfo(IMetaInfo metaInfo)
Sets theIMetaInfo
that will be used duringPdfDocument
creation.- Parameters:
metaInfo
- meta info to set- Returns:
- this
PdfEncryptor
instance
-
setEncryptionProperties
public PdfEncryptor setEncryptionProperties(EncryptionProperties properties)
Sets theEncryptionProperties
- Parameters:
properties
- the properties to set- Returns:
- this
PdfEncryptor
instance
-
encrypt
public void encrypt(PdfReader reader, java.io.OutputStream os, java.util.Map<java.lang.String,java.lang.String> newInfo)
Entry point to encrypt a PDF document.- Parameters:
reader
- the read PDFos
- the output destinationnewInfo
- an optionalString
map to add or change the info dictionary. Entries withnull
values delete the key in the original info dictionary
-
encrypt
public void encrypt(PdfReader reader, java.io.OutputStream os)
Entry point to encrypt a PDF document.- Parameters:
reader
- the read PDFos
- the output destination
-
-