Metadata and Utilities
Metadata and Utilities
Aspose.PDF FOSS for .NET includes utility classes for metadata access, coordinate geometry, image collections, and page-level artifacts. These building blocks support higher-level operations throughout the library.
XMP metadata
Metadata on a document provides access to the XMP metadata stream. Read and
write standard or custom XMP properties.
using var doc = Document.Open(pdfBytes);
// Read existing metadata
foreach (var entry in doc.Metadata)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}
// Set a custom property
doc.Metadata.Add("xmp:CustomProp", new XmpValue("custom value"));
doc.Save("with-metadata.pdf");Coordinate geometry
Rectangle and Matrix are used throughout the API for positioning and
transformation.
var rect = new Rectangle(72, 700, 300, 720);
bool inside = rect.ContainsPoint(150, 710);
// Transformation matrix (translate by 100, 200)
var matrix = new Matrix(1, 0, 0, 1, 100, 200);Page collection operations
PageCollection supports indexing, iteration, and visitor-pattern acceptance.
using var doc = Document.Open(pdfBytes);
for (int i = 1; i <= doc.Pages.Count; i++)
{
var page = doc.Pages[i];
}Image collections
XImageCollection manages images embedded in a page’s resources. XImage
provides methods for inspecting image properties.
var images = doc.Pages[1].Resources.Images;
foreach (var img in images)
{
Console.WriteLine($"Color type: {img.GetColorType()}");
}Artifacts
Artifact represents non-content elements like watermarks, headers, and
footers. Use artifacts for page numbering and decorative elements.
var artifact = new Artifact(ArtifactType.Watermark);
artifact.SetPageNumberReplacementString("Page {0}");Tips and Best Practices
- XMP metadata keys follow the Dublin Core and XMP specifications — use standard namespace prefixes.
Rectanglecoordinates are in PDF user-space units (1/72 inch), with origin at bottom-left.- Use
Matrixfor affine transformations: translation, rotation, scaling, and shearing. XmpValuesupports string, integer, double, date, and array types.- Artifacts are structural elements — they do not appear in accessibility tree traversals.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| Metadata key not found | Key uses a different namespace prefix | List all keys first to find the correct prefix |
| Rectangle coordinates seem inverted | PDF origin is bottom-left, not top-left | Adjust Y coordinates accordingly |
| Image collection is empty | Images are in form XObjects, not direct page resources | Check XFormCollection for nested image resources |
FAQ
How do I read the document title from metadata?
Access doc.Metadata["dc:title"] for the Dublin Core title property.
Can I add a watermark artifact?
Yes. Create an Artifact with type Watermark and add it to the page.
What coordinate system does Rectangle use?
PDF user-space: origin at bottom-left, units of 1/72 inch. A standard US Letter page is 612 x 792 units.
API Reference Summary
| Class / Method | Description |
|---|---|
Metadata | XMP metadata dictionary on the document |
XmpValue | Typed wrapper for XMP property values |
Rectangle | Axis-aligned bounding box (llx, lly, urx, ury) |
Rectangle.ContainsPoint | Test whether a point lies inside the rectangle |
Matrix | 2D affine transformation matrix |
Matrix.Translate | Create a translation matrix |
PageCollection | Ordered page collection with 1-based indexing |
XImageCollection | Image resources on a page |
XImage | Single embedded image with color-type detection |
Artifact | Non-content page element (watermark, header, footer) |
Artifact.SetPageNumberReplacementString | Template for page-number artifacts |