How to Extract and Manage PDF Metadata in .NET
How to Extract and Manage PDF Metadata in .NET
This guide shows how to read and write XMP metadata and work with utility classes in Aspose.PDF FOSS for .NET.
Prerequisites
| Requirement | Detail |
|---|---|
| Runtime | .NET 8.0 or later |
| Package | dotnet add package Aspose.Pdf.Foss |
Read XMP metadata
The Document.Metadata dictionary exposes all XMP properties stored in the
PDF. Iterate its entries to inspect standard Dublin Core fields such as
dc:title, dc:creator, and xmp:CreateDate, or any custom properties
that were previously embedded.
using var doc = Document.Open(pdfBytes);
foreach (var entry in doc.Metadata)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}Set a custom metadata property
Add or update an XMP property by calling Metadata.Add with a key string
and an XmpValue wrapper. Save the document to persist the change.
doc.Metadata.Add("xmp:CustomProp", new XmpValue("value"));
doc.Save("with-metadata.pdf");Work with rectangles
The Rectangle class represents a bounding box used throughout the library
for page geometry, annotation placement, and hit testing. Use ContainsPoint
to check whether a coordinate falls inside the rectangle.
var rect = new Rectangle(72, 700, 300, 720);
bool inside = rect.ContainsPoint(150, 710);Key Classes
| Class | Purpose |
|---|---|
Metadata | XMP metadata dictionary |
XmpValue | Typed metadata value |
Rectangle | Bounding box |
Matrix | Affine transformation |
XImageCollection | Page image resources |
Artifact | Watermark/header/footer elements |