Working with XMP EPS Metadata

Add, edit and get metadata of EPS files with C# API

 

XMP metadata is a set of properties that characterizes the file and is represented in XML format. It contains file information that describes the content of the file and identifications that allow distinguishing this file from other files. It also stores data about creation and modification, users who somehow took part in creating, changing, and uploading the file, and the history of the transformation of the file.

Aspose.Page API solution among the different other features allows working XMP metadata of EPS files. Here you will find information that explains how to add, edit and get it. Learn more examples of how to work with XMP metadata . Try also our XMP Metadata Editor web app, to see how the functionality may be used.

Steps to add XMP metadata to EPS file C#

  1. Set the path to the documents directory.
  2. Initialize an EPS file input stream.
  3. Create an PS file from a stream using the PsDocument Class .
  4. To get XMP metadata use the GetXmpMetadata() Method.
  5. Save the changed EPS document using the Save() Method.

C# Code to add XMP metadata

    using Aspose.Page.EPS;
    using Aspose.Page.EPS.Device;
    using Aspose.Page.EPS.XMP;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize an 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 the PsDocument instance from the stream
    PsDocument document = new PsDocument(psStream);            

    try
    {
        // Get XMP metadata. If the 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();

        // Check metadata values extracted from PS metadata comments and set up in new XMP metadata

        // Get the "CreatorTool" value
        if (xmp.Contains("xmp:CreatorTool"))
        Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());

        // Get the "CreateDate" value
        if (xmp.Contains("xmp:CreateDate"))
            Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());

        // Get the "format" value
        if (xmp.Contains("dc:format"))
            Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());

        // Get the "title" value
        if (xmp.Contains("dc:title"))
            Console.WriteLine("Title: " + xmp["dc:title"].ToArray()[0].ToStringValue());

        // Get the "creator" value
        if (xmp.Contains("dc:creator"))
            Console.WriteLine("Creator: " + xmp["dc:creator"].ToArray()[0].ToStringValue());

        // Get the "MetadataDate" value
        if (xmp.Contains("xmp:MetadataDate"))
            Console.WriteLine("MetadataDate: " + xmp["xmp:MetadataDate"].ToStringValue());

        // Save the EPS file with new XMP metadata

        // Create the ouput stream
        using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "add_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
        {
            // Save the EPS file
            document.Save(outPsStream);
        }

    }
    finally
    {
        psStream.Close();
    }

Steps to edit XMP metadata to EPS file C#

  1. Set the path to the documents directory.
  2. Initialize an EPS file input stream.
  3. Create an PS file from a stream using the PsDocument Class.
  4. To get XMP metadata use the GetXmpMetadata() Method.
  5. To change XMP metadata values use the SetArrayItem() Method.
  6. Save the changed EPS file.

C# Code to change XMP metadata

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize an 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 a PsDocument instance from the stream
    PsDocument document = new PsDocument(psStream);            

    try
    {
        // Get XMP metadata. If the 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 the XMP metadata values

        // Change the title item at index 0
        xmp.SetArrayItem("dc:title", 0, new XmpValue("NewTitle"));

        // Change the creator item at index 0
        xmp.SetArrayItem("dc:creator", 0, new XmpValue("NewCreator"));

        // Save the EPS file with the changed XMP metadata

        // Create an ouput stream
        using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "change_array_items_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
        {
            // Save the EPS file
            document.Save(outPsStream);
        }

    }
    finally
    {
        psStream.Close();
    }

Steps to get XMP metadata of EPS file C#

  1. Set the path to the documents directory.
  2. Initialize an EPS file input stream.
  3. Create an PS file from a stream using the PsDocument Class.
  4. Get XMP metadata using the GetXmpMetadata() Method.

C# Code to get XMP metadata

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize an 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 a PsDocument instance from the stream
    PsDocument document = new PsDocument(psStream);            

    try
    {
        // Get XMP metadata. If the 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 the "CreatorTool" value
        if (xmp.Contains("xmp:CreatorTool"))
            Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
                
        // Get the "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 the "Format" value
        if (xmp.Contains("dc:format"))
            Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());

        // Get the "DocumentID" value
        if (xmp.Contains("xmpMM:DocumentID"))
            Console.WriteLine("DocumentID: " + xmp["xmpMM:DocumentID"].ToStringValue());

    }
    finally
    {
        psStream.Close();
    }



FAQ

1. What is XMP Metadata?

XMP is an abbreviation for Extensible Metadata Platform, - a standard for embedding metadata properties in media files.

2. What information is included in XMP?

There is information about the author, editor, and creator of the application with the version, title, description, keywords, identifiers that allow uniquely identifying the file and history info.

3. How to add XMP metadata to an EPS file?

Set the path to the documents directory and create the EPS file from a stream. To add XMP metadata use the Add() Methods of the XmpMetadata Class.

EPS What is EPS File Format

EPS (EPSF) or Encapsulated PostScript File Format is the format that is actually a PS program that describes what would a single page look like. It is actually limited PS plus particular notes that help encapsulate PostScript graphics to another document. EPS perfectly supports vector graphics or combined vector-raster graphics. The peculiarity of the format is that as soon as it is imported into a document, it cannot be edited anymore. That is one of the reasons to convert this format to the one you are able to work with.