LLION/ PDF, print & document engineering

PDF metadata

LLION Editorial · Updated

A PDF can carry its title in two places that know nothing about each other. The older one is the document information dictionary, a plain PDF dictionary hanging off the trailer. The newer one is an XMP packet, an XML document stored in a stream and attached to the catalog. Most files written since the mid-2000s have both, many files disagree between them, and every tool you use picks one or the other without telling you. Knowing which is which explains most "the title I set does not show up" reports.

Two places for the same facts#

The trailer points to the Info dictionary and the catalog points to the XMP metadata stream; both carry a title trailer/Info /Root Info dictionary/Title (Quarterly report)/ModDate (D:2026…) Catalog/Metadata Metadata stream (XMP)/Type /Metadata /Subtype /XML<dc:title>…Quarterly report…<xmp:ModifyDate>2026-… PDF 1.0 onwardspreferred until PDF 1.7 PDF 1.4 onwards, preferred in PDF 2.0
Two independent stores. The trailer reaches the Info dictionary directly; the XMP stream is reached through the document catalog.

ISO 32000-1 §14.3.1 names both mechanisms and says in a note that the information dictionary is the original method and metadata streams, introduced in PDF 1.4, are "now the preferred method". Neither is required. A file with neither is valid, and viewers then show the file name as the title.

The Info dictionary#

The trailer's /Info entry points at a dictionary whose keys are listed in Table 317 of ISO 32000-1. All are optional except that /ModDate becomes required when the catalog has a /PieceInfo entry.

Entries of the document information dictionary, ISO 32000-1 Table 317.
KeyTypeMeaning
/Titletext stringDocument title (PDF 1.1)
/Authortext stringPerson who created the document
/Subjecttext stringSubject (PDF 1.1)
/Keywordstext stringKeywords, one string; the separator is not specified
/Creatortext stringApplication that made the original document, if converted
/Producertext stringApplication that converted it to PDF (the PDF library, usually)
/CreationDatedateCreation date and time
/ModDatedateLast modification date and time (PDF 1.1)
/Trappedname/True, /False or /Unknown: whether trapping information was added for print (PDF 1.3)

Any other key is allowed and must hold a text string; the specification asks that custom keys be spelled out rather than abbreviated, and forbids using the dictionary for private structural data.

Here is the dictionary pdf-lib wrote for the example file generated for this page, exactly as it appears in the file:

Info dictionary written by pdf-lib 1.17.1 (object 3)PDF syntax
<<
/Producer <FEFF007000640066002D006C0069006200200031002E00310037002E0031>
/ModDate (D:20261029093000Z)
/Creator <FEFF004C004C0049004F004E002E004E004500540020006500780061006D0070006C00650020007300630072006900700074>
/CreationDate (D:20261029093000Z)
/Title <FEFF0051007500610072007400650072006C00790020007200650070006F00720074>
/Author <FEFF004500780061006D0070006C006500200041007500740068006F0072>
/Subject <FEFF004D0065007400610064006100740061002000640065006D006F006E007300740072006100740069006F006E>
/Keywords <FEFF0070006400660020006D006500740061006400610074006100200078006D0070>
>>

The hex strings are not obfuscation. A text string in PDF 1.7 (Table 35) is encoded either in PDFDocEncoding, a single-byte Latin encoding, or in UTF-16BE with a leading byte order mark, which is the FEFF at the start of each value. pdf-lib chooses UTF-16BE for everything, so Quarterly report becomes 0051 0075 0061 …. A library that reads the dictionary must check for the mark; one that writes it must choose an encoding that covers the characters in the value, which rules out PDFDocEncoding for anything beyond Western European text. PDF 2.0 adds UTF-8 with a byte order mark (EF BB BF) as a third option, and the PDF Association notes that older viewers may show those three bytes as stray characters.

Dates are the other encoding to get right.

The date format#

A PDF date (§7.9.4) is a text string of the form D:YYYYMMDDHHmmSSOHH'mm, read left to right with every field optional after the year, but only if all preceding fields are present. O is the relationship to universal time: +, - or Z. The hour offset is followed by an apostrophe; the minute offset follows it.

PDF date stringsText
D:20261029093000Z          2026-10-29 09:30:00 UTC
D:20261029113000+02'00     the same instant written in Central European Summer Time
D:199812231952-08'00       ISO 32000-1's own example: 23 Dec 1998, 19:52, US Pacific Standard Time
D:2026                     1 January 2026, 00:00:00, offset unknown (defaults apply)

Missing month and day default to 01; missing time fields default to zero. If no offset is given, the time is to be treated as GMT, yet the fields are still "local time", a phrase that has produced many off-by-timezone bugs in libraries. Older PDF 1.7 documentation ended the string with a second apostrophe after the minutes (-08'00'); ISO 32000-1 dropped it, and readers accept both. pdf-lib writes Z for UTC; pypdf's documentation builds strings with strftime and an explicit -05'00' offset. When you parse, accept both forms; when you write, use UTC with Z unless the local offset matters to the reader.

The XMP metadata stream#

The catalog's /Metadata entry points at a stream whose dictionary has /Type /Metadata and /Subtype /XML (Table 315). The content is an XMP packet: RDF/XML wrapped in <?xpacket begin="" …?> and <?xpacket end="w"?> processing instructions. Properties are grouped by namespace: Dublin Core (dc:title, dc:creator, dc:description, dc:subject), the XMP basic schema (xmp:CreateDate, xmp:ModifyDate, xmp:MetadataDate, xmp:CreatorTool), the PDF schema (pdf:Producer, pdf:Keywords), and the identification schemas used by PDF/A, PDF/X and PDF/UA.

XMP packet in the example file (abridged)HTML
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
   <dc:title><rdf:Alt><rdf:li xml:lang="x-default">Quarterly report</rdf:li></rdf:Alt></dc:title>
   <dc:creator><rdf:Seq><rdf:li>Example Author</rdf:li></rdf:Seq></dc:creator>
   <xmp:CreateDate>2026-10-29T09:30:00.000Z</xmp:CreateDate>
   <xmp:ModifyDate>2026-10-29T09:30:00.000Z</xmp:ModifyDate>
   <pdf:Producer>pdf-lib 1.17.1</pdf:Producer>
  </rdf:Description>
 </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>

Two conventions follow from the packet's purpose. It is left uncompressed, so that a tool with no PDF parser can find it by scanning the file for <?xpacket; ISO 32000-1 notes that this only works if the stream is "both unfiltered and unencrypted", and the PDF 2.0 errata add that XMP in PDF shall be UTF-8. And it carries its own date stamp (xmp:MetadataDate), which the precedence rule below relies on. Note the different date syntax: XMP uses ISO 8601 (2026-10-29T09:30:00Z), not the PDF D: form, so a writer that keeps both in sync is converting between two formats.

Components can carry their own metadata streams too: images, fonts, ICC profiles and form XObjects may each have a /Metadata entry (Table 316), which is how a photograph's camera data can survive inside a PDF.

Which copy wins#

ISO 32000-1 §14.3.2 gives a rule rather than a preference. If the XMP packet's date stamp is equal to or later than the Info dictionary's /ModDate, the metadata stream is authoritative. If /ModDate is later, the document "has likely been saved by a writer that is not aware of metadata streams", and the Info dictionary overrides the semantically equivalent XMP items. In other words, the newer copy wins, with ties going to XMP.

PDF 2.0 settles the question for new files. The public summaries of ISO 32000-2 agree that the document information dictionary is deprecated in favour of the metadata stream, with every key except /CreationDate and /ModDate deprecated; the PDF Association's errata for clause 14 state that "metadata streams are the preferred method in PDF 2.0". Deprecated in ISO 32000-2's vocabulary means a writer should not produce it and a reader should ignore it, so a 2.0 writer puts titles and authors in XMP only. PDF/A went further earlier: every PDF/A part requires an XMP packet, requires the Info dictionary values, if present, to match it, and PDF/A-4 drops the Info dictionary altogether.

For anyone writing files today the practical rule is simple: write both, with identical values, and set the XMP date stamp to the modification time. Readers of any age then agree.

What metadata leaks#

Metadata travels with the file, and most of it was never typed in by the person sending it.

  • /Author is filled by word processors from the operating-system account name or the licence holder; corporate files routinely carry the name of whoever installed the template years earlier.
  • /Creator and /Producer reveal the software and version, which is useful for attackers choosing an exploit and for anyone fingerprinting a document's origin.
  • XMP history (xmpMM:History, stEvt:* entries) can list every application that touched the file and the original file paths and names, including pre-redaction titles.
  • Component metadata on images keeps camera make, GPS coordinates and capture times if the producer did not strip them.
  • The incremental update history is not metadata in the formal sense, but it is the most common leak of all: earlier versions of pages, including text that was later "deleted", stay in the file until it is rewritten.

A viewer's document properties panel shows the Info dictionary and, in some viewers, a merged view with XMP. It does not show component metadata or history. exiftool -a -G1 file.pdf lists everything, grouped by where it was found.

Reading and writing#

pdf-lib (JavaScript, browser or Node). The high-level setters write the Info dictionary only; pdf-lib 1.17.1 has no XMP API. The example file for this page was produced as follows, with the XMP packet added through the low-level object API. Note the two save options: without updateMetadata: false, pdf-lib overwrites /Producer with its own name and /ModDate with the current time on every save.

metadata-demo.mjs (pdf-lib 1.17.1, run with Node 26, output verified with qpdf)JavaScript
import { PDFDocument, PDFName } from 'pdf-lib';

const doc = await PDFDocument.create();
doc.setTitle('Quarterly report');
doc.setAuthor('Example Author');
doc.setSubject('Metadata demonstration');
doc.setKeywords(['pdf', 'metadata', 'xmp']);
doc.setCreator('LLION.NET example script');
doc.setProducer('pdf-lib 1.17.1');
const when = new Date('2026-10-29T09:30:00Z');
doc.setCreationDate(when);
doc.setModificationDate(when);
doc.addPage([595.28, 841.89]);

// XMP has to be written by hand: a stream with /Type /Metadata /Subtype /XML on the catalog.
const xmp = `<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<dc:title><rdf:Alt><rdf:li xml:lang="x-default">Quarterly report</rdf:li></rdf:Alt></dc:title>
<xmp:CreateDate>${when.toISOString()}</xmp:CreateDate><xmp:ModifyDate>${when.toISOString()}</xmp:ModifyDate>
</rdf:Description></rdf:RDF></x:xmpmeta>
<?xpacket end="w"?>`;
const stream = doc.context.stream(Buffer.from(xmp, 'utf8'), { Type: 'Metadata', Subtype: 'XML' });
doc.catalog.set(PDFName.of('Metadata'), doc.context.register(stream));

const bytes = await doc.save({ updateMetadata: false });
// Reading back:
const again = await PDFDocument.load(bytes, { updateMetadata: false });
console.log(again.getTitle(), again.getAuthor(), again.getCreationDate());
// Quarterly report Example Author 2026-10-29T09:30:00.000Z

pypdf (Python). reader.metadata returns the Info dictionary with attribute access and parsed dates; reader.xmp_metadata returns the XMP packet as an object with dc_title, xmp_create_date and similar properties; writer.add_metadata() takes a dictionary of Info keys. Checked against the pypdf documentation, not executed here.

metadata.py (pypdf 6, checked against the pypdf documentation, not executed)Python
from datetime import datetime, timezone
from pypdf import PdfReader, PdfWriter

reader = PdfReader("in.pdf")
info = reader.metadata                 # may be None
print(info.title, info.author, info.creation_date)
xmp = reader.xmp_metadata              # None if the file has no XMP stream
if xmp:
    print(xmp.dc_title, xmp.xmp_create_date)

writer = PdfWriter(clone_from=reader)
now = datetime.now(timezone.utc).strftime("D:%Y%m%d%H%M%SZ")
writer.add_metadata({"/Title": "Quarterly report", "/Author": "Example Author", "/ModDate": now})
writer.write("out.pdf")

ExifTool. Reads both stores and writes them with an incremental update, which makes the edit reversible (exiftool -PDF-update:all= file.pdf restores the original) and means the old values are still in the file until it is rewritten by a PDF tool.

Shell
exiftool -a -G1 file.pdf                       # everything, with the group it came from (PDF vs XMP-dc vs XMP-xmp)
exiftool -Title="Quarterly report" -Author="Example Author" file.pdf

qpdf. qpdf --json=2 file.pdf prints the Info dictionary as part of the trailer and object listing; text strings appear with a u: prefix once decoded.

Removing metadata properly#

Three layers have to be removed, and they need different tools.

Shell
# 1. Info dictionary and XMP stream, then rewrite the file so that no earlier revision remains
qpdf --remove-info --remove-metadata --object-streams=generate in.pdf out.pdf

# 2. ExifTool clears Info and XMP (as an incremental update: the originals are still inside)
exiftool -all= in.pdf
# ...so follow it with a rewrite that drops the update history:
qpdf --linearize in.pdf out.pdf

The third layer is component metadata on images and fonts and any xmpMM:History; exiftool -all= removes what it can see, but embedded ICC profile descriptions and font names stay because they are content, not metadata. If the file must be clean, the reliable route is to re-create it from the page content with a tool that does not copy document-level dictionaries, for example qpdf --empty --pages in.pdf -- out.pdf, and then to verify with exiftool -a -G1 that nothing identifying remains. Encrypting the file is not a substitute: ISO 32000-1 lets a writer leave the metadata stream unencrypted on purpose (/EncryptMetadata false, see encryption) so that indexing tools can still read it.

Inspecting metadata from the command line#

Shell
qpdf --json=2 file.pdf | grep -A12 '"/Info"'                 # the Info dictionary, decoded
qpdf --qdf --object-streams=disable file.pdf - | grep -A30 '/Type /Metadata'   # the raw XMP packet
exiftool -a -G1 -s file.pdf                                     # every field, with its source group
grep -c '%%EOF' file.pdf                                        # number of revisions in the file

The PDF inspector reports the Info dictionary, whether an XMP stream exists, and the revision count for any file, in the browser.

Sources