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.
  • Rectangle coordinates are in PDF user-space units (1/72 inch), with origin at bottom-left.
  • Use Matrix for affine transformations: translation, rotation, scaling, and shearing.
  • XmpValue supports string, integer, double, date, and array types.
  • Artifacts are structural elements — they do not appear in accessibility tree traversals.

Common Issues

IssueCauseFix
Metadata key not foundKey uses a different namespace prefixList all keys first to find the correct prefix
Rectangle coordinates seem invertedPDF origin is bottom-left, not top-leftAdjust Y coordinates accordingly
Image collection is emptyImages are in form XObjects, not direct page resourcesCheck 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 / MethodDescription
MetadataXMP metadata dictionary on the document
XmpValueTyped wrapper for XMP property values
RectangleAxis-aligned bounding box (llx, lly, urx, ury)
Rectangle.ContainsPointTest whether a point lies inside the rectangle
Matrix2D affine transformation matrix
Matrix.TranslateCreate a translation matrix
PageCollectionOrdered page collection with 1-based indexing
XImageCollectionImage resources on a page
XImageSingle embedded image with color-type detection
ArtifactNon-content page element (watermark, header, footer)
Artifact.SetPageNumberReplacementStringTemplate for page-number artifacts

See Also