Blog

 7 minute read.

ExifTool

Tony Hammond

Tony Hammond – 2007 August 27

In Metadata

<span >(<b>Update - 2007.08.28:</b> I inadvertently missed out the term names in the last example of XMP as RDF/N3 with QNames and have now added these in. Also - a biggie - I said that PRISM had no XMP schema defined. This is actually wrong and as I blogged <a href="/blog/stop-press/">here</a> today, the new PRISM 2.0 spec does indeed have a mapping of PRISM terms to XMP value types. Should actually have read the spec instead of just blogging about it earlier <a href="/blog/prism-2.0/">here</a>. :~)

<span >Having previously stooped to an extremely crass hack for pulling out a document information dictionary from PDFs (for which no apologies are sufficient but it does often work) I feel I should make some kind of amends and mention the wonderful <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/">ExifTool</a> by Phil Harvey for reading and writing metadata to media files. This is both a Perl library and command-line application (so it’s cross-platform - a Windows .exe and Mac OS .dmg are also provided.) Besides handling EXIF tags in image files this veritable swissknife of metadata inspectors can also read PDFs for the information dictionary and the document XMP packet. And moreover, intriguingly, can dump the raw (document) XMP packet.

<span >I’m still experimenting with it. There’s quite a number of features to explore. But some preliminary finds are listed below.

<span >Taking one of our standard (metadata poor) PDFs we get this dump:

% exiftool nature05428.pdf
ExifTool Version Number         : 6.95
File Name                       : nature05428.pdf
Directory                       : .
File Size                       : 367 kB
File Modification Date/Time     : 2007:07:26 14:01:23
File Type                       : PDF
MIME Type                       : application/pdf
Page Count                      : 3
Producer                        : Acrobat Distiller 6.0.1 (Windows)
Mod Date                        : 2006:12:19 15:03:23+08:00
Creation Date                   : 2006:12:18 16:57:58+08:00
Creator                         : 3B2 Total Publishing System 7.51n/W
Creator Tool                    : 3B2 Total Publishing System 7.51n/W
Modify Date                     : 2006:12:19 15:03:23+08:00
Create Date                     : 2006:12:18 16:57:58+08:00
Metadata Date                   : 2006:12:19 15:03:23+08:00
Document ID                     : uuid:f598740b-ad11-41c5-a49e-7caffea783f0
Format                          : application/pdf
Title                           : untitled

<span >By way of comparison, if we take a demo (metadata rich) PDF with added descriptive DC and PRISM metadata terms, we then get this dump:

% exiftool 445037a.pdf
ExifTool Version Number         : 6.95
File Name                       : 445037a.pdf
Directory                       : .
File Size                       : 265 kB
File Modification Date/Time     : 2007:07:26 16:18:17
File Type                       : PDF
MIME Type                       : application/pdf
Page Count                      : 1
Creator Tool                    : InDesign: pictwpstops filter 1.0
Metadata Date                   : 2006:12:22 12:10:07Z
Document ID                     : uuid:4cd39128-2c8e-41c0-9cad-eea2a1fdb64f
Identifier                      : doi:10.1038/445037a
Description                     : doi:10.1038/445037a
Source                          : Nature 445, 37 (2007)
Date                            : 2007:01:04
Format                          : application/pdf
Publisher                       : Nature Publishing Group
Language                        : en
Rights                          : © 2007 Nature Publishing Group
Publication Name                : Nature
Issn                            : 0028-0836
E Issn                          : 1476-4679
Publication Date                : 2007-01-04
Copyright                       : © 2007 Nature Publishing Group
Rights Agent                    : permissions@nature.com
Volume                          : 445
Number                          : 7123
Starting Page                   : 37
Ending Page                     : 37
Section                         : News and Views
Modify Date                     : 2006:12:22 12:10:07Z
Create Date                     : 2006:12:22 11:46:18Z
Title                           : 4.1 N&V NS NEW.indd
Trapped                         : False
Creator                         : InDesign: pictwpstops filter 1.0
GTS PDFX Version                : PDF/X-1:2001
GTS PDFX Conformance            : PDF/X-1a:2001
Author                          : x
Producer                        : Acrobat Distiller 6.0.1 for Macintosh

<span >Note that the DC and PRISM terms are encoded as my earlier examples and do not take account of a) how DC is defined as an XMP schema (i.e. the XMP value types for the seperate terms), or b) how PRISM <i>might</i> (because it isn’t yet) be defined as an XMP schema. Nor are identifier considerations fully taken into account. Nonetheless this gives more than an idea of what things could look like.

<span >Now, with ExifTool it is also possible to list out the terms by group, e.g.

% exiftool -g1 445037a.pdf
---- ExifTool ----
ExifTool Version Number         : 6.95
---- File ----
File Name                       : 445037a.pdf
Directory                       : .
File Size                       : 265 kB
File Modification Date/Time     : 2007:07:26 16:18:17
File Type                       : PDF
MIME Type                       : application/pdf
---- PDF ----
Page Count                      : 1
Modify Date                     : 2006:12:22 12:10:07Z
Create Date                     : 2006:12:22 11:46:18Z
Title                           : 4.1 N&V NS NEW.indd
Trapped                         : False
Creator                         : InDesign: pictwpstops filter 1.0
GTS PDFX Version                : PDF/X-1:2001
GTS PDFX Conformance            : PDF/X-1a:2001
Author                          : x
Producer                        : Acrobat Distiller 6.0.1 for Macintosh
---- XMP-xmp ----
Creator Tool                    : InDesign: pictwpstops filter 1.0
Metadata Date                   : 2006:12:22 12:10:07Z
---- XMP-xmpMM ----
Document ID                     : uuid:4cd39128-2c8e-41c0-9cad-eea2a1fdb64f
---- XMP-dc ----
Identifier                      : doi:10.1038/445037a
Description                     : doi:10.1038/445037a
Source                          : Nature 445, 37 (2007)
Date                            : 2007:01:04
Format                          : application/pdf
Publisher                       : Nature Publishing Group
Language                        : en
Rights                          : © 2007 Nature Publishing Group
---- XMP-prism ----
Publication Name                : Nature
Issn                            : 0028-0836
E Issn                          : 1476-4679
Publication Date                : 2007-01-04
Copyright                       : © 2007 Nature Publishing Group
Rights Agent                    : permissions@nature.com
Volume                          : 445
Number                          : 7123
Starting Page                   : 37
Ending Page                     : 37
Section                         : News and Views

<span >Going back to the first example we can extract the (document) XMP packet as:

% exiftool -xmp -b nature05428.pdf



Acrobat Distiller 6.0.1 (Windows)
2006-12-19T15:03:23+08:00
2006-12-18T16:57:58+08:00
untitled
3B2 Total Publishing System 7.51n/W


3B2 Total Publishing System 7.51n/W
2006-12-19T15:03:23+08:00
2006-12-18T16:57:58+08:00
application/pdf


untitled


2006-12-19T15:03:23+08:00


uuid:f598740b-ad11-41c5-a49e-7caffea783f0


application/pdf
untitled


%

<span >Note that this PDF also included XMP packets for illustrations but the tool extracted the main, or document, XMP packet.

<span >And now that it’s easier to extract the metadata one can look to do something more interesting. For example, if one has <a href="http://www.w3.org/2000/10/swap/doc/cwm">cwm</a> installed (Tim BL’s Closed World Machine for semweb dabblings - a Python application, so again cross-platform) one can pipe the XMP packet into cwm as RDF/XML, verify it as valid RDF and read out in another format, e.g. RDF/N3. For the above example we can so this as follows.

<span >But let me first define a pipeline to extract the XMP, a couple filters to strip out processing instructions (includes the open and close bracketing <?xpacket> XMP PI’s as well as an undocumented - legacy? - <?adobe> Adobe PI), and then fed into cwm as RDF/XML and read out as RDF/N3. (Note that instead of ExifTool to extract the XMP another tool could have been used, e.g. something based on the sample apps shipped with the Adobe XMP SDK, or something bespoke.)

% alias get_n3
exiftool -xmp -b !$ | grep -v "

<span >We can then simply request to get the metadata from this PDF in RDF/N3 format:

% get_n3 nature05428.pdf
#Processed by Id: cwm.py,v 1.164 2004/10/28 17:41:59 timbl Exp
#    using base file:/Users/tony/Xcode/xmp/dev/
#  Notation3 generation by
#       notation3.py,v 1.166 2004/10/28 17:41:59 timbl Exp
#   Base was: file:/Users/tony/Xcode/xmp/dev/
@prefix rdf:  .
      "2006-12-18T16:57:58+08:00";
 "3B2 Total Publishing System 7.51n/W";
 "2006-12-19T15:03:23+08:00";
 "Acrobat Distiller 6.0.1 (Windows)";
 "untitled";
 "2006-12-18T16:57:58+08:00";
 "3B2 Total Publishing System 7.51n/W";
 "application/pdf";
 "2006-12-19T15:03:23+08:00";
 "2006-12-19T15:03:23+08:00";
  [
a rdf:Alt;
rdf:_1 "untitled"@x-default ];
 "uuid:f598740b-ad11-41c5-a49e-7caffea783f0";
 "application/pdf";
 "untitled" .
#ENDS

<span >Or writing that out again with QNames for readability (and dropping the UUID as RDF subject as recommended by latest XMP spec) we have:

#Processed by Id: cwm.py,v 1.164 2004/10/28 17:41:59 timbl Exp
#    using base file:/Users/tony/Xcode/xmp/dev/
#  Notation3 generation by
#       notation3.py,v 1.166 2004/10/28 17:41:59 timbl Exp
#   Base was: file:/Users/tony/Xcode/xmp/dev/
@prefix dc:  .
@prefix pdf:  .
@prefix xmp:  .
@prefix xmpMM:  .
<>    pdf:CreationDate "2006-12-18T16:57:58+08:00";
pdf:Creator "3B2 Total Publishing System 7.51n/W";
pdf:ModDate "2006-12-19T15:03:23+08:00";
pdf:Producer "Acrobat Distiller 6.0.1 (Windows)";
pdf:Title "untitled";
xmp:CreateDate "2006-12-18T16:57:58+08:00";
xmp:CreatorTool "3B2 Total Publishing System 7.51n/W";
xmp:Format "application/pdf";
xmp:MetadataDate "2006-12-19T15:03:23+08:00";
xmp:ModifyDate "2006-12-19T15:03:23+08:00";
xmp:Title  [
a rdf:Alt;
rdf:_1 "untitled"@x-default ];
xmpMM:DocumentID "uuid:f598740b-ad11-41c5-a49e-7caffea783f0";
dc:format "application/pdf";
dc:title "untitled" .
#ENDS

<span >Now just imagine that there were something a little more interesting in there. Like a DOI. Like descriptive metadata, perhaps. 🙂

Related pages and blog posts

Page owner: Tony Hammond   |   Last updated 2007-August-27