Skip to content

Commit b07a840

Browse files
committed
Override XMP document info properties.
DEVSIX-594
1 parent ff177b5 commit b07a840

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

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

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -302,40 +302,26 @@ protected XMPMeta createXmpMetadata() throws XMPException {
302302
continue;
303303
value = ((PdfString) obj).toUnicodeString();
304304
if (PdfName.Title.equals(key)) {
305-
if (!IsXmpMetaHasLocalizedText(xmpMeta, XMPConst.NS_DC, PdfConst.Title)) {
306-
xmpMeta.setLocalizedText(XMPConst.NS_DC, PdfConst.Title, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, value);
307-
}
305+
xmpMeta.setLocalizedText(XMPConst.NS_DC, PdfConst.Title, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, value);
308306
} else if (PdfName.Author.equals(key)) {
309307
xmpMeta.appendArrayItem(XMPConst.NS_DC, PdfConst.Creator, new PropertyOptions(PropertyOptions.ARRAY_ORDERED), value, null);
310308
} else if (PdfName.Subject.equals(key)) {
311-
if (!IsXmpMetaHasLocalizedText(xmpMeta, XMPConst.NS_DC, PdfConst.Description)) {
312-
xmpMeta.setLocalizedText(XMPConst.NS_DC, PdfConst.Description, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, value);
313-
}
309+
xmpMeta.setLocalizedText(XMPConst.NS_DC, PdfConst.Description, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, value);
314310
} else if (PdfName.Keywords.equals(key)) {
315311
for (String v : value.split(",|;")) {
316312
if (v.trim().length() > 0) {
317313
xmpMeta.appendArrayItem(XMPConst.NS_DC, PdfConst.Subject, new PropertyOptions(PropertyOptions.ARRAY), v.trim(), null);
318314
}
319315
}
320-
if (!isXmpMetaHasProperty(xmpMeta, XMPConst.NS_PDF, PdfConst.Keywords)) {
321-
xmpMeta.setProperty(XMPConst.NS_PDF, PdfConst.Keywords, value);
322-
}
316+
xmpMeta.setProperty(XMPConst.NS_PDF, PdfConst.Keywords, value);
323317
} else if (PdfName.Creator.equals(key)) {
324-
if (!isXmpMetaHasProperty(xmpMeta, XMPConst.NS_PDF, PdfConst.CreatorTool)) {
325-
xmpMeta.setProperty(XMPConst.NS_XMP, PdfConst.CreatorTool, value);
326-
}
318+
xmpMeta.setProperty(XMPConst.NS_XMP, PdfConst.CreatorTool, value);
327319
} else if (PdfName.Producer.equals(key)) {
328-
if (!isXmpMetaHasProperty(xmpMeta, XMPConst.NS_PDF, PdfConst.Producer)) {
329-
xmpMeta.setProperty(XMPConst.NS_PDF, PdfConst.Producer, value);
330-
}
320+
xmpMeta.setProperty(XMPConst.NS_PDF, PdfConst.Producer, value);
331321
} else if (PdfName.CreationDate.equals(key)) {
332-
if (!isXmpMetaHasProperty(xmpMeta, XMPConst.NS_XMP, PdfConst.CreateDate)) {
333-
xmpMeta.setProperty(XMPConst.NS_XMP, PdfConst.CreateDate, PdfDate.getW3CDate(value));
334-
}
322+
xmpMeta.setProperty(XMPConst.NS_XMP, PdfConst.CreateDate, PdfDate.getW3CDate(value));
335323
} else if (PdfName.ModDate.equals(key)) {
336-
if (!isXmpMetaHasProperty(xmpMeta, XMPConst.NS_XMP, PdfConst.ModifyDate)) {
337-
xmpMeta.setProperty(XMPConst.NS_XMP, PdfConst.ModifyDate, PdfDate.getW3CDate(value));
338-
}
324+
xmpMeta.setProperty(XMPConst.NS_XMP, PdfConst.ModifyDate, PdfDate.getW3CDate(value));
339325
}
340326
}
341327
}
@@ -1698,10 +1684,6 @@ private static boolean isXmpMetaHasProperty(XMPMeta xmpMeta, String schemaNS, St
16981684
return xmpMeta.getProperty(schemaNS, propName) != null;
16991685
}
17001686

1701-
private static boolean IsXmpMetaHasLocalizedText(XMPMeta xmpMeta, String schemaNS, String altTextName) throws XMPException {
1702-
return xmpMeta.getLocalizedText(schemaNS, altTextName, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT) != null;
1703-
}
1704-
17051687
@SuppressWarnings("unused")
17061688
private byte[] getSerializedBytes() {
17071689
ByteArrayOutputStream bos = null;

0 commit comments

Comments
 (0)