Skip to content

Commit 57a88d5

Browse files
committed
Add method to set writer property PDF/UA
Set PDF/UA version flags ONLY when user manually sets this flag with writer propeties. DEVSIX-629
1 parent 2248ca9 commit 57a88d5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ protected XMPMeta updateDefaultXmpMetadata() throws XMPException {
18451845
XMPMeta xmpMeta = XMPMetaFactory.parseFromBuffer(getXmpMetadata(true));
18461846
XmpMetaInfoConverter.appendDocumentInfoToMetadata(info, xmpMeta);
18471847

1848-
if (isTagged() && !isXmpMetaHasProperty(xmpMeta, XMPConst.NS_PDFUA_ID, XMPConst.PART)) {
1848+
if (isTagged() && writer.properties.pdfUA && !isXmpMetaHasProperty(xmpMeta, XMPConst.NS_PDFUA_ID, XMPConst.PART)) {
18491849
xmpMeta.setPropertyInteger(XMPConst.NS_PDFUA_ID, XMPConst.PART, 1, new PropertyOptions(PropertyOptions.SEPARATE_NODE));
18501850
}
18511851

kernel/src/main/java/com/itextpdf/kernel/pdf/WriterProperties.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class WriterProperties implements Serializable {
6464
protected boolean smartMode;
6565
protected boolean debugMode;
6666
protected boolean addXmpMetadata;
67+
protected boolean pdfUA;
6768
protected PdfVersion pdfVersion;
6869
protected EncryptionProperties encryptionProperties;
6970
/**
@@ -79,6 +80,7 @@ public class WriterProperties implements Serializable {
7980
public WriterProperties() {
8081
smartMode = false;
8182
debugMode = false;
83+
pdfUA = false;
8284
compressionLevel = CompressionConstants.DEFAULT_COMPRESSION;
8385
isFullCompression = null;
8486
encryptionProperties = new EncryptionProperties();
@@ -182,7 +184,7 @@ public WriterProperties setStandardEncryption(byte[] userPassword, byte[] ownerP
182184
* <p>
183185
* @param certs the public certificates to be used for the encryption
184186
* @param permissions the user permissions for each of the certificates
185-
* @param encryptionType the type of encryption. It can be one of {@link EncryptionConstants#STANDARD_ENCRYPTION_40},
187+
* @param encryptionAlgorithm the type of encryption. It can be one of {@link EncryptionConstants#STANDARD_ENCRYPTION_40},
186188
* {@link EncryptionConstants#STANDARD_ENCRYPTION_128}, {@link EncryptionConstants#ENCRYPTION_AES_128}
187189
* or {@link EncryptionConstants#ENCRYPTION_AES_256}.
188190
* Optionally {@link EncryptionConstants#DO_NOT_ENCRYPT_METADATA} can be ORed to output the metadata in cleartext
@@ -234,6 +236,18 @@ public WriterProperties useDebugMode() {
234236
return this;
235237
}
236238

239+
/**
240+
* This method marks the document as PDF/UA and sets related flags is XMPMetaData.
241+
* NOTE: iText does not validate PDF/UA, which means we don't check if created PDF meets all PDF/UA requirements.
242+
* 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.
243+
*
244+
* @return this {@code WriterProperties} instance
245+
*/
246+
public WriterProperties setPdfUA() {
247+
this.pdfUA = true;
248+
return this;
249+
}
250+
237251
boolean isStandardEncryptionUsed() {
238252
return encryptionProperties.isStandardEncryptionUsed();
239253
}

0 commit comments

Comments
 (0)