Class WriterProperties
- java.lang.Object
-
- com.itextpdf.kernel.pdf.WriterProperties
-
public class WriterProperties extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected PdfAConformanceaddPdfAXmpMetadataprotected PdfUAConformanceaddPdfUaXmpMetadataprotected booleanaddXmpMetadataprotected intcompressionLevelprotected EncryptionPropertiesencryptionPropertiesprotected PdfStringinitialDocumentIdThe ID entry that represents the initial identifier.protected java.lang.BooleanisFullCompressionIndicates if to use full compression (using object streams).protected PdfStringmodifiedDocumentIdThe ID entry that represents a change in a document.protected PdfVersionpdfVersionprotected booleansmartModeIndicates if the writer copy objects in a smart mode.
-
Constructor Summary
Constructors Constructor Description WriterProperties()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WriterPropertiesaddPdfAXmpMetadata(PdfAConformance aConformance)Adds PDF/A XMP metadata to the PDF document.WriterPropertiesaddPdfUaXmpMetadata(PdfUAConformance uaConformance)Adds PDF/UA XMP metadata to the PDF document.WriterPropertiesaddXmpMetadata()If true, default XMPMetadata based onPdfDocumentInfowill be added.(package private) booleanisPublicKeyEncryptionUsed()(package private) booleanisStandardEncryptionUsed()WriterPropertiessetCompressionLevel(int compressionLevel)Defines the level of compression for the document.WriterPropertiessetFullCompressionMode(boolean fullCompressionMode)Defines if full compression mode is enabled.WriterPropertiessetInitialDocumentId(PdfString initialDocumentId)The /ID entry of a document contains an array with two entries.WriterPropertiessetModifiedDocumentId(PdfString modifiedDocumentId)The /ID entry of a document contains an array with two entries.WriterPropertiessetPdfVersion(PdfVersion version)Defines pdf version for the created document.WriterPropertiessetPublicKeyEncryption(java.security.cert.Certificate[] certs, int[] permissions, int encryptionAlgorithm)Sets the certificate encryption options for the document.WriterPropertiessetPublicKeyEncryption(java.security.cert.Certificate[] certs, int[] permissions, int encryptionAlgorithm, MacProperties macProperties)Sets the certificate encryption options for the document.WriterPropertiessetStandardEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionAlgorithm)Sets the encryption options for the document.WriterPropertiessetStandardEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionAlgorithm, MacProperties macProperties)Sets the encryption options for the document.WriterPropertiesuseSmartMode()Enables smart mode.
-
-
-
Field Detail
-
compressionLevel
protected int compressionLevel
-
isFullCompression
protected java.lang.Boolean isFullCompression
Indicates if to use full compression (using object streams).
-
smartMode
protected boolean smartMode
Indicates 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
-
addPdfAXmpMetadata
protected PdfAConformance addPdfAXmpMetadata
-
addPdfUaXmpMetadata
protected PdfUAConformance addPdfUaXmpMetadata
-
pdfVersion
protected PdfVersion pdfVersion
-
encryptionProperties
protected EncryptionProperties encryptionProperties
-
initialDocumentId
protected PdfString initialDocumentId
The ID entry that represents the initial identifier.
-
modifiedDocumentId
protected PdfString modifiedDocumentId
The ID entry that represents a change in a document.
-
-
Method Detail
-
setPdfVersion
public WriterProperties setPdfVersion(PdfVersion version)
Defines pdf version for the created document. Default value is PDF_1_7.- Parameters:
version- version for the document.- Returns:
- this
WriterPropertiesinstance
-
useSmartMode
public WriterProperties 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
WriterPropertiesinstance
-
addXmpMetadata
public WriterProperties addXmpMetadata()
If true, default XMPMetadata based onPdfDocumentInfowill be added. For PDF 2.0 documents, metadata will be added in any case.- Returns:
- this
WriterPropertiesinstance
-
addPdfAXmpMetadata
public WriterProperties addPdfAXmpMetadata(PdfAConformance aConformance)
Adds PDF/A XMP metadata to the PDF document.This method calls
addXmpMetadata()implicitly.NOTE: Calling this method only affects the XMP metadata, but doesn't enable any additional checks that the created document meets all PDF/A requirements. When using this method make sure you are familiar with PDF/A document requirements. If you are not sure, use dedicated iText PDF/A module to create valid PDF/A documents.
- Parameters:
aConformance- the PDF/A conformance which will be added to XMP metadata- Returns:
- this
WriterPropertiesinstance
-
addPdfUaXmpMetadata
public WriterProperties addPdfUaXmpMetadata(PdfUAConformance uaConformance)
Adds PDF/UA XMP metadata to the PDF document.This method calls
addXmpMetadata()implicitly.NOTE: Calling this method only affects the XMP metadata, but doesn't enable any additional checks that the created document meets all PDF/UA requirements. When using this method make sure you are familiar with PDF/UA document requirements. If you are not sure, use dedicated iText PDF/UA module to create valid PDF/UA documents.
- Parameters:
uaConformance- the PDF/UA conformance which will be added to XMP metadata- Returns:
- this
WriterPropertiesinstance
-
setCompressionLevel
public WriterProperties setCompressionLevel(int compressionLevel)
Defines the level of compression for the document. SeeCompressionConstants- Parameters:
compressionLevel-CompressionConstantsvalue.- Returns:
- this
WriterPropertiesinstance
-
setFullCompressionMode
public WriterProperties setFullCompressionMode(boolean fullCompressionMode)
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
WriterPropertiesinstance
-
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 passwordownerPassword- the owner password. If it's null or empty, iText will generate a random string to be used as the owner passwordpermissions- 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_ASSEMBLYandEncryptionConstants.ALLOW_DEGRADED_PRINTING. The permissions can be combined by ORing themencryptionAlgorithm- the type of encryption. It can be one ofEncryptionConstants.STANDARD_ENCRYPTION_40,EncryptionConstants.STANDARD_ENCRYPTION_128,EncryptionConstants.ENCRYPTION_AES_128,EncryptionConstants.ENCRYPTION_AES_256orEncryptionConstants.ENCRYPTION_AES_GCM. OptionallyEncryptionConstants.DO_NOT_ENCRYPT_METADATAcan be ORed to output the metadata in cleartext.EncryptionConstants.EMBEDDED_FILES_ONLYcan be ORed as well. Please be aware that the passed encryption types may override permissions:EncryptionConstants.STANDARD_ENCRYPTION_40implicitly setsEncryptionConstants.DO_NOT_ENCRYPT_METADATAandEncryptionConstants.EMBEDDED_FILES_ONLYas false;EncryptionConstants.STANDARD_ENCRYPTION_128implicitly setsEncryptionConstants.EMBEDDED_FILES_ONLYas false;- Returns:
- this
WriterPropertiesinstance
-
setStandardEncryption
public WriterProperties setStandardEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionAlgorithm, MacProperties macProperties)
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 passwordownerPassword- the owner password. If it's null or empty, iText will generate a random string to be used as the owner passwordpermissions- 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_ASSEMBLYandEncryptionConstants.ALLOW_DEGRADED_PRINTING. The permissions can be combined by ORing themencryptionAlgorithm- the type of encryption. It can be one ofEncryptionConstants.STANDARD_ENCRYPTION_40,EncryptionConstants.STANDARD_ENCRYPTION_128,EncryptionConstants.ENCRYPTION_AES_128,EncryptionConstants.ENCRYPTION_AES_256orEncryptionConstants.ENCRYPTION_AES_GCM. OptionallyEncryptionConstants.DO_NOT_ENCRYPT_METADATAcan be ORed to output the metadata in cleartext.EncryptionConstants.EMBEDDED_FILES_ONLYcan be ORed as well. Please be aware that the passed encryption types may override permissions:EncryptionConstants.STANDARD_ENCRYPTION_40implicitly setsEncryptionConstants.DO_NOT_ENCRYPT_METADATAandEncryptionConstants.EMBEDDED_FILES_ONLYas false;EncryptionConstants.STANDARD_ENCRYPTION_128implicitly setsEncryptionConstants.EMBEDDED_FILES_ONLYas false;macProperties-MacPropertiesclass to configure MAC integrity protection properties. Passnullif you want to disable MAC protection for any reason- Returns:
- this
WriterPropertiesinstance
-
setPublicKeyEncryption
public WriterProperties setPublicKeyEncryption(java.security.cert.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 encryptionpermissions- 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_ASSEMBLYandEncryptionConstants.ALLOW_DEGRADED_PRINTING. The permissions can be combined by ORing themencryptionAlgorithm- the type of encryption. It can be one ofEncryptionConstants.STANDARD_ENCRYPTION_40,EncryptionConstants.STANDARD_ENCRYPTION_128,EncryptionConstants.ENCRYPTION_AES_128,EncryptionConstants.ENCRYPTION_AES_256orEncryptionConstants.ENCRYPTION_AES_GCM. OptionallyEncryptionConstants.DO_NOT_ENCRYPT_METADATAcan be ORed to output the metadata in cleartext.EncryptionConstants.EMBEDDED_FILES_ONLYcan be ORed as well. Please be aware that the passed encryption types may override permissions:EncryptionConstants.STANDARD_ENCRYPTION_40implicitly setsEncryptionConstants.DO_NOT_ENCRYPT_METADATAandEncryptionConstants.EMBEDDED_FILES_ONLYas false;EncryptionConstants.STANDARD_ENCRYPTION_128implicitly setsEncryptionConstants.EMBEDDED_FILES_ONLYas false;- Returns:
- this
WriterPropertiesinstance
-
setPublicKeyEncryption
public WriterProperties setPublicKeyEncryption(java.security.cert.Certificate[] certs, int[] permissions, int encryptionAlgorithm, MacProperties macProperties)
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 encryptionpermissions- 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_ASSEMBLYandEncryptionConstants.ALLOW_DEGRADED_PRINTING. The permissions can be combined by ORing themencryptionAlgorithm- the type of encryption. It can be one ofEncryptionConstants.STANDARD_ENCRYPTION_40,EncryptionConstants.STANDARD_ENCRYPTION_128,EncryptionConstants.ENCRYPTION_AES_128,EncryptionConstants.ENCRYPTION_AES_256orEncryptionConstants.ENCRYPTION_AES_GCM. OptionallyEncryptionConstants.DO_NOT_ENCRYPT_METADATAcan be ORed to output the metadata in cleartext.EncryptionConstants.EMBEDDED_FILES_ONLYcan be ORed as well. Please be aware that the passed encryption types may override permissions:EncryptionConstants.STANDARD_ENCRYPTION_40implicitly setsEncryptionConstants.DO_NOT_ENCRYPT_METADATAandEncryptionConstants.EMBEDDED_FILES_ONLYas false;EncryptionConstants.STANDARD_ENCRYPTION_128implicitly setsEncryptionConstants.EMBEDDED_FILES_ONLYas false;macProperties-MacPropertiesclass to configure MAC integrity protection properties. Passnullif you want to disable MAC protection for any reason- Returns:
- this
WriterPropertiesinstance
-
setInitialDocumentId
public WriterProperties setInitialDocumentId(PdfString initialDocumentId)
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 recommended 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
WriterPropertiesinstance
-
setModifiedDocumentId
public WriterProperties setModifiedDocumentId(PdfString modifiedDocumentId)
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
WriterPropertiesinstance
-
isStandardEncryptionUsed
boolean isStandardEncryptionUsed()
-
isPublicKeyEncryptionUsed
boolean isPublicKeyEncryptionUsed()
-
-