@@ -275,62 +275,6 @@ public void setXmpMetadata(XMPMeta xmpMeta) throws XMPException {
275
275
setXmpMetadata (xmpMeta , serializeOptions );
276
276
}
277
277
278
- protected void updateXmpMetadata () {
279
- try {
280
- if (writer .properties .addXmpMetadata ) {
281
- setXmpMetadata (createXmpMetadata ());
282
- }
283
- } catch (XMPException e ) {
284
- Logger logger = LoggerFactory .getLogger (PdfDocument .class );
285
- logger .error (LogMessageConstant .EXCEPTION_WHILE_UPDATING_XMPMETADATA , e );
286
- }
287
- }
288
-
289
- protected XMPMeta createXmpMetadata () throws XMPException {
290
- XMPMeta xmpMeta = XMPMetaFactory .parseFromBuffer (getXmpMetadata (true ));
291
- PdfDictionary docInfo = info .getPdfObject ();
292
- if (docInfo != null ) {
293
- PdfName key ;
294
- PdfObject obj ;
295
- String value ;
296
- for (PdfName pdfName : docInfo .keySet ()) {
297
- key = pdfName ;
298
- obj = docInfo .get (key );
299
- if (obj == null )
300
- continue ;
301
- if (obj .getType () != PdfObject .STRING )
302
- continue ;
303
- value = ((PdfString ) obj ).toUnicodeString ();
304
- if (PdfName .Title .equals (key )) {
305
- xmpMeta .setLocalizedText (XMPConst .NS_DC , PdfConst .Title , XMPConst .X_DEFAULT , XMPConst .X_DEFAULT , value );
306
- } else if (PdfName .Author .equals (key )) {
307
- xmpMeta .appendArrayItem (XMPConst .NS_DC , PdfConst .Creator , new PropertyOptions (PropertyOptions .ARRAY_ORDERED ), value , null );
308
- } else if (PdfName .Subject .equals (key )) {
309
- xmpMeta .setLocalizedText (XMPConst .NS_DC , PdfConst .Description , XMPConst .X_DEFAULT , XMPConst .X_DEFAULT , value );
310
- } else if (PdfName .Keywords .equals (key )) {
311
- for (String v : value .split (",|;" )) {
312
- if (v .trim ().length () > 0 ) {
313
- xmpMeta .appendArrayItem (XMPConst .NS_DC , PdfConst .Subject , new PropertyOptions (PropertyOptions .ARRAY ), v .trim (), null );
314
- }
315
- }
316
- xmpMeta .setProperty (XMPConst .NS_PDF , PdfConst .Keywords , value );
317
- } else if (PdfName .Creator .equals (key )) {
318
- xmpMeta .setProperty (XMPConst .NS_XMP , PdfConst .CreatorTool , value );
319
- } else if (PdfName .Producer .equals (key )) {
320
- xmpMeta .setProperty (XMPConst .NS_PDF , PdfConst .Producer , value );
321
- } else if (PdfName .CreationDate .equals (key )) {
322
- xmpMeta .setProperty (XMPConst .NS_XMP , PdfConst .CreateDate , PdfDate .getW3CDate (value ));
323
- } else if (PdfName .ModDate .equals (key )) {
324
- xmpMeta .setProperty (XMPConst .NS_XMP , PdfConst .ModifyDate , PdfDate .getW3CDate (value ));
325
- }
326
- }
327
- }
328
- if (isTagged () && !isXmpMetaHasProperty (xmpMeta , XMPConst .NS_PDFUA_ID , XMPConst .PART )) {
329
- xmpMeta .setPropertyInteger (XMPConst .NS_PDFUA_ID , XMPConst .PART , 1 , new PropertyOptions (PropertyOptions .SEPARATE_NODE ));
330
- }
331
- return xmpMeta ;
332
- }
333
-
334
278
/**
335
279
* Gets XMPMetadata.
336
280
*/
@@ -1445,6 +1389,62 @@ protected void open(PdfVersion newPdfVersion) {
1445
1389
}
1446
1390
}
1447
1391
1392
+ protected void updateXmpMetadata () {
1393
+ try {
1394
+ if (writer .properties .addXmpMetadata ) {
1395
+ setXmpMetadata (updateDefaultXmpMetadata ());
1396
+ }
1397
+ } catch (XMPException e ) {
1398
+ Logger logger = LoggerFactory .getLogger (PdfDocument .class );
1399
+ logger .error (LogMessageConstant .EXCEPTION_WHILE_UPDATING_XMPMETADATA , e );
1400
+ }
1401
+ }
1402
+
1403
+ protected XMPMeta updateDefaultXmpMetadata () throws XMPException {
1404
+ XMPMeta xmpMeta = XMPMetaFactory .parseFromBuffer (getXmpMetadata (true ));
1405
+ PdfDictionary docInfo = info .getPdfObject ();
1406
+ if (docInfo != null ) {
1407
+ PdfName key ;
1408
+ PdfObject obj ;
1409
+ String value ;
1410
+ for (PdfName pdfName : docInfo .keySet ()) {
1411
+ key = pdfName ;
1412
+ obj = docInfo .get (key );
1413
+ if (obj == null )
1414
+ continue ;
1415
+ if (obj .getType () != PdfObject .STRING )
1416
+ continue ;
1417
+ value = ((PdfString ) obj ).toUnicodeString ();
1418
+ if (PdfName .Title .equals (key )) {
1419
+ xmpMeta .setLocalizedText (XMPConst .NS_DC , PdfConst .Title , XMPConst .X_DEFAULT , XMPConst .X_DEFAULT , value );
1420
+ } else if (PdfName .Author .equals (key )) {
1421
+ xmpMeta .appendArrayItem (XMPConst .NS_DC , PdfConst .Creator , new PropertyOptions (PropertyOptions .ARRAY_ORDERED ), value , null );
1422
+ } else if (PdfName .Subject .equals (key )) {
1423
+ xmpMeta .setLocalizedText (XMPConst .NS_DC , PdfConst .Description , XMPConst .X_DEFAULT , XMPConst .X_DEFAULT , value );
1424
+ } else if (PdfName .Keywords .equals (key )) {
1425
+ for (String v : value .split (",|;" )) {
1426
+ if (v .trim ().length () > 0 ) {
1427
+ xmpMeta .appendArrayItem (XMPConst .NS_DC , PdfConst .Subject , new PropertyOptions (PropertyOptions .ARRAY ), v .trim (), null );
1428
+ }
1429
+ }
1430
+ xmpMeta .setProperty (XMPConst .NS_PDF , PdfConst .Keywords , value );
1431
+ } else if (PdfName .Creator .equals (key )) {
1432
+ xmpMeta .setProperty (XMPConst .NS_XMP , PdfConst .CreatorTool , value );
1433
+ } else if (PdfName .Producer .equals (key )) {
1434
+ xmpMeta .setProperty (XMPConst .NS_PDF , PdfConst .Producer , value );
1435
+ } else if (PdfName .CreationDate .equals (key )) {
1436
+ xmpMeta .setProperty (XMPConst .NS_XMP , PdfConst .CreateDate , PdfDate .getW3CDate (value ));
1437
+ } else if (PdfName .ModDate .equals (key )) {
1438
+ xmpMeta .setProperty (XMPConst .NS_XMP , PdfConst .ModifyDate , PdfDate .getW3CDate (value ));
1439
+ }
1440
+ }
1441
+ }
1442
+ if (isTagged () && !isXmpMetaHasProperty (xmpMeta , XMPConst .NS_PDFUA_ID , XMPConst .PART )) {
1443
+ xmpMeta .setPropertyInteger (XMPConst .NS_PDFUA_ID , XMPConst .PART , 1 , new PropertyOptions (PropertyOptions .SEPARATE_NODE ));
1444
+ }
1445
+ return xmpMeta ;
1446
+ }
1447
+
1448
1448
/**
1449
1449
* List all newly added or loaded fonts
1450
1450
*
0 commit comments