Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/19604c3796dec399d8b54cd292262fc0 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/19604c3796dec399d8b54cd292262fc0 to your computer and use it in GitHub Desktop.
Add, change and update XMP metadata in EPS file with .NET

Work with XMP Metadata in EPS Examples

These snippets show how to read, create, and update XMP metadata in EPS using Aspose.Page for .NET. Manage Dublin Core fields and custom properties, synchronize with PS comments, and embed descriptive information for archival and search.

Key Use Cases

  • How to read XMP metadata from an EPS file
  • How to create XMP packets (CreatorTool, CreateDate, Thumbnails, etc.)
  • How to change XMP properties values (title, creator, ModifyDate)
  • How to add custom properties and namespaces and synchronize with PS metadata

How to Run Examples

  1. Reference Aspose.Page for .NET: Aspose.Page on Windows; Aspose.Page.Drawing on non‑Windows.
  2. Copy a snippet into your project or run the related test.
  3. Apply a temporary license as described in the licensing guide.
  4. Build and run.

Restrictions

In evaluation mode, the input EPS file is limited to 500Kb. Apply a valid license to unlock full functionality.

Related Documentation

See more about working with XMP metadata in EPS files in Working with XMP Metadata in EPS files | .NET chapter of our tutorial.

Related Resources

Requirements

  • .NET 6.0+, .NET Core, or .NET Framework
  • Aspose.Page for .NET library
Aspose.Page for .NET – Add XMP Metadata in EPS Examples
// Add XMP metadata to EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream. Given EPS file doesn't contain XMP metadata, but usual metadata does contain.
PsDocument document = new PsDocument(psStream);
string outputFileName = "add_xmp_metadata_out.eps";
XmpMetadata xmp = null;
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
xmp = document.GetXmpMetadata();
// Check metadata values extracted from PS metadata comments and set up in new XMP metadata
// Get "CreatorTool" value
if (xmp.Contains("xmp:CreatorTool"))
Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
// Get "CreateDate" value
if (xmp.Contains("xmp:CreateDate"))
Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
// Get "format" value
if (xmp.Contains("dc:format"))
Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
// Get "title" value
if (xmp.Contains("dc:title"))
Console.WriteLine("Title: " + xmp["dc:title"].ToArray()[0].ToStringValue());
// Get "creator" value
if (xmp.Contains("dc:creator"))
Console.WriteLine("Creator: " + xmp["dc:creator"].ToArray()[0].ToStringValue());
// Get "MetadataDate" value
if (xmp.Contains("xmp:MetadataDate"))
Console.WriteLine("MetadataDate: " + xmp["xmp:MetadataDate"].ToStringValue());
// Update MetadataDate value
DateTime metadataDate = xmp["xmp:MetadataDate"].ToDateTime();
// Save EPS file with new XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Add array items in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "add_xmp_array_items_out.eps";
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Add one more title. I will be added at the end of array by default.
xmp.AddArrayItem("dc:title", new XmpValue("NewTitle"));
// Add one more creator. It will be added in the array by an index (0).
xmp.AddArrayItem("dc:creator", 0, new XmpValue("NewCreator"));
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Add named value in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_named_value_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "add_xmp_named_value_out.eps";
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Add named value to "xmpTPg:MaxPageSize" structure.
xmp.AddNamedValue("xmpTPg:MaxPageSize", "stDim:newKey", new XmpValue("NewValue"));
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Add namespace in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "add_xmp_namespace_out.eps";
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Add new XML namespace "tmp".
xmp.RegisterNamespaceUri("tmp", "http://www.some.org/schema/tmp#");
// Add new string property in new namespace.
xmp.Add("tmp:newKey", new XmpValue("NewValue"));
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Add simple properties in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "add_xmp_simple_props_out.eps";
DateTime now = DateTime.UtcNow;
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Add Integer poperty
xmp.Add("xmp:Intg1", new XmpValue(111));
// Add DateTime poperty
xmp.Add("xmp:Date1", new XmpValue(now));
// Add Double poperty
xmp.Add("xmp:Double1", new XmpValue(111.11D));
// Add String poperty
xmp.Add("xmp:String1", new XmpValue("ABC"));
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Change array items in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "change_xmp_array_items_out.eps";
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Change title item at index 0
xmp.SetArrayItem("dc:title", 0, new XmpValue("NewTitle"));
// Change creator item at index 0
xmp.SetArrayItem("dc:creator", 0, new XmpValue("NewCreator"));
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Change named value in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_named_value_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "change_xmp_named_value_out.eps";
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Change named value "stDim:unit" in "xmpTPg:MaxPageSize" structure.
xmp.SetNamedValue("xmpTPg:MaxPageSize", "stDim:unit", new XmpValue("Inches"));
// Add named value "stDim:newKey" in "xmpTPg:MaxPageSize" structure.
xmp.SetNamedValue("xmpTPg:MaxPageSize", "stDim:newKey", new XmpValue("NewValue"));
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Change values in XMP metadata in EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Initialize EPS file input stream
System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "get_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Create PsDocument instance from stream
PsDocument document = new PsDocument(psStream);
string outputFileName = "change_values_out.eps";
DateTime now = DateTime.UtcNow;
try
{
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
//Change XMP metadata values
// Change ModifyDate value
xmp["xmp:ModifyDate"] = now;
// Change Creator value
XmpValue value = new XmpValue("Aspose.Page");
xmp.Add("dc:creator", value);
// Change Title value
value = new XmpValue("(change_values.eps)");
xmp.Add("dc:title", value);
// Save EPS file with changed XMP metadata
// Create ouput stream
using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Save EPS file
document.Save(outPsStream);
}
}
finally
{
psStream.Close();
}
// Get XMP metadata from EPS document.
// Learn more: https://docs.aspose.com/page/net/working-with-xm-metadata-in-eps/
// Create PsDocument instance from file
PsDocument document = new PsDocument(DataDir + "get_input.eps");
// Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
XmpMetadata xmp = document.GetXmpMetadata();
// Get "CreatorTool" value
if (xmp.Contains("xmp:CreatorTool"))
Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
// Get "CreateDate" value
if (xmp.Contains("xmp:CreateDate"))
Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
// Get a width of a thumbnail image if exists
if (xmp.Contains("xmp:Thumbnails") && xmp["xmp:Thumbnails"].IsArray)
{
XmpValue val = xmp["xmp:Thumbnails"].ToArray()[0];
if (val.IsNamedValues && val.ToDictionary().ContainsKey("xmpGImg:width"))
Console.WriteLine($"Thumbnail Width: {val.ToDictionary()["xmpGImg:width"].ToInteger()}");
}
// Get "format" value
if (xmp.Contains("dc:format"))
Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
// Get "DocumentID" value
if (xmp.Contains("xmpMM:DocumentID"))
Console.WriteLine("DocumentID: " + xmp["xmpMM:DocumentID"].ToStringValue());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment