Package com.itextpdf.kernel.pdf
Class WriterProperties
java.lang.Object
com.itextpdf.kernel.pdf.WriterProperties
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected boolean
protected int
protected EncryptionProperties
protected PdfString
The ID entry that represents the initial identifier.protected Boolean
Indicates if to use full compression (using object streams).protected PdfString
The ID entry that represents a change in a document.protected PdfVersion
protected boolean
Indicates if the writer copy objects in a smart mode. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionThis method marks the document as PDF/UA and sets related flags is XMPMetaData.If true, default XMPMetadata based onPdfDocumentInfo
will be added.setCompressionLevel
(int compressionLevel) Defines the level of compression for the document.setFullCompressionMode
(boolean fullCompressionMode) Defines if full compression mode is enabled.setInitialDocumentId
(PdfString initialDocumentId) The /ID entry of a document contains an array with two entries.setModifiedDocumentId
(PdfString modifiedDocumentId) The /ID entry of a document contains an array with two entries.setPdfVersion
(PdfVersion version) Defines pdf version for the created document.setPublicKeyEncryption
(Certificate[] certs, int[] permissions, int encryptionAlgorithm) Sets the certificate encryption options for the document.setStandardEncryption
(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionAlgorithm) Sets the encryption options for the document.Enables smart mode.
-
Field Details
-
compressionLevel
protected int compressionLevel -
isFullCompression
Indicates if to use full compression (using object streams). -
smartMode
protected boolean smartModeIndicates if the writer copy objects in a smart mode. If so PdfDictionary and PdfStream will be hashed and reused if there's an object with the same content later. -
addXmpMetadata
protected boolean addXmpMetadata -
addUAXmpMetadata
protected boolean addUAXmpMetadata -
pdfVersion
-
encryptionProperties
-
initialDocumentId
The ID entry that represents the initial identifier. -
modifiedDocumentId
The ID entry that represents a change in a document.
-
-
Constructor Details
-
WriterProperties
public WriterProperties()
-
-
Method Details
-
setPdfVersion
Defines pdf version for the created document. Default value is PDF_1_7.- Parameters:
-
version
- version for the document. - Returns:
-
this
WriterProperties
instance
-
useSmartMode
Enables smart mode.
In smart mode when resources (such as fonts, images,...) are encountered, a reference to these resources is saved in a cache, so that they can be reused. This requires more memory, but reduces the file size of the resulting PDF document.- Returns:
-
this
WriterProperties
instance
-
addXmpMetadata
If true, default XMPMetadata based onPdfDocumentInfo
will be added. For PDF 2.0 documents, metadata will be added in any case.- Returns:
-
this
WriterProperties
instance
-
setCompressionLevel
Defines the level of compression for the document. SeeCompressionConstants
- Parameters:
-
compressionLevel
-CompressionConstants
value. - Returns:
-
this
WriterProperties
instance
-
setFullCompressionMode
Defines if full compression mode is enabled. If enabled, not only the content of the pdf document will be compressed, but also the pdf document inner structure.- Parameters:
-
fullCompressionMode
- true - to enable full compression mode, false to disable it - Returns:
-
this
WriterProperties
instance
-
setStandardEncryption
public WriterProperties setStandardEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionAlgorithm) Sets the encryption options for the document.- Parameters:
-
userPassword
- the user password. Can be null or of zero length, which is equal to omitting the user password -
ownerPassword
- the owner password. If it's null or empty, iText will generate a random string to be used as the owner password -
permissions
- the user permissions The open permissions for the document can beEncryptionConstants.ALLOW_PRINTING
,EncryptionConstants.ALLOW_MODIFY_CONTENTS
,EncryptionConstants.ALLOW_COPY
,EncryptionConstants.ALLOW_MODIFY_ANNOTATIONS
,EncryptionConstants.ALLOW_FILL_IN
,EncryptionConstants.ALLOW_SCREENREADERS
,EncryptionConstants.ALLOW_ASSEMBLY
andEncryptionConstants.ALLOW_DEGRADED_PRINTING
. The permissions can be combined by ORing them -
encryptionAlgorithm
- the type of encryption. It can be one ofEncryptionConstants.STANDARD_ENCRYPTION_40
,EncryptionConstants.STANDARD_ENCRYPTION_128
,EncryptionConstants.ENCRYPTION_AES_128
orEncryptionConstants.ENCRYPTION_AES_256
. OptionallyEncryptionConstants.DO_NOT_ENCRYPT_METADATA
can be ORed to output the metadata in cleartext.EncryptionConstants.EMBEDDED_FILES_ONLY
can be ORed as well. Please be aware that the passed encryption types may override permissions:EncryptionConstants.STANDARD_ENCRYPTION_40
implicitly setsEncryptionConstants.DO_NOT_ENCRYPT_METADATA
andEncryptionConstants.EMBEDDED_FILES_ONLY
as false;EncryptionConstants.STANDARD_ENCRYPTION_128
implicitly setsEncryptionConstants.EMBEDDED_FILES_ONLY
as false; - Returns:
-
this
WriterProperties
instance
-
setPublicKeyEncryption
public WriterProperties setPublicKeyEncryption(Certificate[] certs, int[] permissions, int encryptionAlgorithm) Sets the certificate encryption options for the document. An array of one or more public certificates must be provided together with an array of the same size for the permissions for each certificate.- Parameters:
-
certs
- the public certificates to be used for the encryption -
permissions
- the user permissions for each of the certificates The open permissions for the document can beEncryptionConstants.ALLOW_PRINTING
,EncryptionConstants.ALLOW_MODIFY_CONTENTS
,EncryptionConstants.ALLOW_COPY
,EncryptionConstants.ALLOW_MODIFY_ANNOTATIONS
,EncryptionConstants.ALLOW_FILL_IN
,EncryptionConstants.ALLOW_SCREENREADERS
,EncryptionConstants.ALLOW_ASSEMBLY
andEncryptionConstants.ALLOW_DEGRADED_PRINTING
. The permissions can be combined by ORing them -
encryptionAlgorithm
- the type of encryption. It can be one ofEncryptionConstants.STANDARD_ENCRYPTION_40
,EncryptionConstants.STANDARD_ENCRYPTION_128
,EncryptionConstants.ENCRYPTION_AES_128
orEncryptionConstants.ENCRYPTION_AES_256
. OptionallyEncryptionConstants.DO_NOT_ENCRYPT_METADATA
can be ORed to output the metadata in cleartext.EncryptionConstants.EMBEDDED_FILES_ONLY
can be ORed as well. Please be aware that the passed encryption types may override permissions:EncryptionConstants.STANDARD_ENCRYPTION_40
implicitly setsEncryptionConstants.DO_NOT_ENCRYPT_METADATA
andEncryptionConstants.EMBEDDED_FILES_ONLY
as false;EncryptionConstants.STANDARD_ENCRYPTION_128
implicitly setsEncryptionConstants.EMBEDDED_FILES_ONLY
as false; - Returns:
-
this
WriterProperties
instance
-
setInitialDocumentId
The /ID entry of a document contains an array with two entries. The first one (initial id) represents the initial document id. It's a permanent identifier based on the contents of the file at the time it was originally created and does not change when the file is incrementally updated. To help ensure the uniqueness of file identifiers, it is recommend to be computed by means of a message digest algorithm such as MD5. iText will by default keep the existing initial id. But if you'd like you can set this id yourself using this setter.- Parameters:
-
initialDocumentId
- the new initial document id - Returns:
-
this
WriterProperties
instance
-
setModifiedDocumentId
The /ID entry of a document contains an array with two entries. The second one (modified id) should be the same entry, unless the document has been modified. iText will by default generate a modified id. But if you'd like you can set this id yourself using this setter.- Parameters:
-
modifiedDocumentId
- the new modified document id - Returns:
-
this
WriterProperties
instance
-
addUAXmpMetadata
This method marks the document as PDF/UA and sets related flags is XMPMetaData. This method callsaddXmpMetadata()
implicitly. NOTE: iText does not validate PDF/UA, which means we don't check if created PDF meets all PDF/UA requirements. Don't use this method if you are not familiar with PDF/UA specification in order to avoid creation of non-conformant PDF/UA file.- Returns:
-
this
WriterProperties
instance
-