Trabajar con metadatos EPS XMP

Agregue, edite y obtenga metadatos de archivos EPS con C#

 

Los metadatos XMP son un conjunto de propiedades que caracterizan el archivo y se representan en formato XML. Contiene información de archivo que describe el contenido del archivo e identificaciones que permiten distinguir este archivo de otros archivos. También almacena datos sobre la creación y modificación, los usuarios que de alguna manera participaron en la creación, modificación y carga del archivo, y el historial de transformación del archivo.

La solución Aspose.Page API, entre otras características, permite trabajar metadatos XMP de archivos EPS. Aquí encontrarás información que explica cómo agregarlo, editarlo y obtenerlo. Obtenga más ejemplos de cómo trabajar con XMP metadata . Pruebe también nuestra aplicación web XMP Metadata Editor para ver cómo se puede usar la funcionalidad.

Pasos para agregar metadatos XMP al archivo EPS C#

  1. Establezca la ruta al directorio de documentos.
  2. Inicialice un flujo de entrada de archivo EPS.
  3. Cree un archivo PS a partir de una transmisión mediante PsDocument Class .
  4. Para obtener metadatos XMP, use el método GetXmpMetadata() .
  5. Guarde el documento EPS modificado con el método Save() .

Código C# para agregar metadatos XMP

    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();
    }

Pasos para editar metadatos XMP en un archivo EPS C#

  1. Establezca la ruta al directorio de documentos.
  2. Inicialice un flujo de entrada de archivo EPS.
  3. Cree un archivo PS a partir de una secuencia utilizando PsDocument Class.
  4. Para obtener metadatos XMP, utilice el método GetXmpMetadata().
  5. Para cambiar los valores de los metadatos XMP, utilice el método SetArrayItem() .
  6. Guarde el archivo EPS modificado.

Código C# para cambiar los metadatos XMP

    // 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();
    }

Pasos para obtener metadatos XMP del archivo EPS C#

  1. Establezca la ruta al directorio de documentos.
  2. Inicialice un flujo de entrada de archivo EPS.
  3. Cree un archivo PS a partir de una secuencia utilizando PsDocument Class.
  4. Obtenga metadatos XMP utilizando el método GetXmpMetadata().

Código C# para obtener metadatos XMP

    // 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();
    }



Preguntas más frecuentes

1. ¿Qué son los metadatos XMP?

XMP es una abreviatura de Extensible Metadata Platform, un estándar para incrustar propiedades de metadatos en archivos multimedia.

2. ¿Qué información se incluye en XMP?

Hay información sobre el autor, editor y creador de la aplicación con la versión, título, descripción, palabras clave, identificadores que permiten identificar de forma única el archivo e información del historial.

3. ¿Cómo agregar metadatos XMP a un archivo EPS?

Establezca la ruta al directorio de documentos y cree el archivo EPS a partir de una secuencia. Para agregar metadatos XMP, utilice los métodos Add() de la clase XmpMetadata.

EPS Qué es EPS Formato de archivo

EPS (ERSF) o formato de archivo PostScript encapsulado es el formato que en realidad es un programa PS que describe cómo se vería una sola página. En realidad, es PS limitado más notas particulares que ayudan a encapsular gráficos PostScript en otro documento. EPS admite perfectamente gráficos vectoriales o gráficos combinados de vector-ráster. La peculiaridad del formato es que tan pronto como se importa a un documento, ya no se puede editar. Esa es una de las razones para convertir este formato al que puede trabajar.