Metadata
editReaders show the title of a document in their window and its properties in a dialog; search engines and document management systems index them. Set them before saving:
var document = new PdfDocument { Language = "en-US" };
document.Information.Title = "Quarterly report";
document.Information.Author = "Finance team";
document.Information.Subject = "The results of the third quarter";
document.Information.Keywords = "finance, report";
document.Information.CreationDate = new DateTimeOffset(2026, 10, 1, 9, 0, 0, TimeSpan.Zero);
document.Information.SetText("Department", "Finance"); // a custom entry
document.Pages.Add(PdfSize.A4);
// PDF 2.0 prefers the XMP metadata: write it from the information above
document.UpdateXmpMetadata();
var pdf = document.ToByteArray();
var read = PdfDocument.Open(pdf);
var title = read.Information.Title;
var department = read.Information.GetText("Department");
var xmp = read.GetXmpMetadata(); // the XMP packet: UTF-8 XML, or nullThe document information
PdfDocument.Information reads and writes the document information dictionary:
- Title, Author, Subject, Keywords, Creator (the application that created the original document) and Producer (the application that converted it to PDF).
- CreationDate and ModificationDate:
nullwhen they are missing or are not valid dates. - Trapped: whether a prepress workflow has added the trapping information (PdfTrapped.True, False or Unknown),
nullwhen the entry is missing. - GetText and SetText read and write any other entry, such as a custom one.
Setting a value to null removes the entry. The library sets none of them by itself, not even the dates or the producer, so that the same document gives the same file: set CreationDate and ModificationDate when you want them.
XMP metadata
PDF 2.0 deprecates every entry of the document information but the dates, in favor of the XMP metadata, an XML packet that other tools read too.
| Method | Does |
|---|---|
| UpdateXmpMetadata | Updates the XMP metadata with the values of Information: title, author, subject, keywords, producer, creator tool, dates and trapping. The other properties of the packet, such as custom schemas, are kept |
| GetXmpMetadata | Returns the packet (UTF-8 XML), or null when the document has none |
| SetXmpMetadata | Sets a packet you wrote. It updates the existing metadata stream, and leaves it unchanged when it already has the packet |
| RemoveXmpMetadata | Removes it |
Call UpdateXmpMetadata after the information is set: it does not follow later changes. A PDF/A document gets its XMP metadata from the information when it is saved, with the identification of its level: see PDF/A.
The values the information sets replace those of the packet: a value the information does not have is removed, so that both agree, except pdf:Trapped, which stays when Trapped is null. To start from an empty packet, call RemoveXmpMetadata first.
XML does not allow the control characters (other than tab, line feed and carriage return) and the lone surrogates: the packet has the replacement character (U+FFFD) in their place. As PDF/A-1, PDF/A-2 and PDF/A-3 need the information and the packet to agree, a save with these levels is refused when the information has such a character.
Reserve space for later edits
Some tools update the packet in place, without rewriting the file: they need whitespace at the end of the packet, which the padding reserves.
// Reserve 2 KB of whitespace in the packet, so that an editor can update it in place
document.UpdateXmpMetadata(padding: 2048);
// The packet a PDF/A or PDF/UA save writes
var options = new PdfSaveOptions { XmpPadding = 2048 };PdfSaveOptions.XmpPadding applies to the packet that a save with a PDF/A or PDF/UA level writes. The padding is spaces, with a line feed every 100 bytes; a packet without padding is the default.
Language
PdfDocument.Language is the natural language of the document, a BCP 47 tag such as en-US or fr-FR. Screen readers use it to choose their pronunciation, and PDF/UA requires it. An element of the structure tree can have a language of its own: see Tagged PDF and PDF/UA.
Version
PdfDocument.Version is the version of the document: the version of the header of the file, or the version of the catalog when it is later. It can be set; a save raises it when the document or the options need a later version (AES-256 encryption needs PDF 2.0, for instance). PdfVersion has the versions from Pdf14 to Pdf20, and TryParse reads a version written as in a header, such as 1.7.