Obtenga metadatos XMP de un archivo EPS usando .NET

Puede comprobar la calidad de los metadatos XMP de Aspose.Page trabajando con la aplicación web Metadata.

Para extraer metadatos XMP de un archivo EPS es necesario seguir varios pasos:

  1. Abra un FileStream (o una instrucción using) para el archivo EPS, por ejemplo, using var stream = new FileStream("sample.eps", FileMode.Open);.
  2. Cree un PsDocument a partir del stream: var document = new PsDocument(stream);.
  3. Recupere los metadatos XMP mediante XmpMetadata xmp = document.XmpMetadata;. Si el EPS no contiene XMP, Aspose crea un nuevo objeto XmpMetadata a partir de los comentarios del archivo EPS.
  4. Acceda a las propiedades de los metadatos, como xmp.Title, xmp.Author y xmp.Description, para leer los valores.

El siguiente fragmento de código muestra cómo extraer metadatos XMP de un archivo EPS en C#:

 1// Get XMP metadata from EPS document.
 2
 3// Create PsDocument instance from file
 4PsDocument document = new PsDocument(DataDir + "get_input.eps");
 5
 6// 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)
 7XmpMetadata xmp = document.GetXmpMetadata();
 8
 9// Get "CreatorTool" value
10if (xmp.Contains("xmp:CreatorTool"))
11    Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
12
13// Get "CreateDate" value
14if (xmp.Contains("xmp:CreateDate"))
15    Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
16
17// Get a width of a thumbnail image if exists
18if (xmp.Contains("xmp:Thumbnails") && xmp["xmp:Thumbnails"].IsArray)
19{
20    XmpValue val = xmp["xmp:Thumbnails"].ToArray()[0];
21    if (val.IsNamedValues && val.ToDictionary().ContainsKey("xmpGImg:width"))
22        Console.WriteLine($"Thumbnail Width: {val.ToDictionary()["xmpGImg:width"].ToInteger()}");
23}
24
25// Get "format" value
26if (xmp.Contains("dc:format"))
27    Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
28
29// Get "DocumentID" value
30if (xmp.Contains("xmpMM:DocumentID"))
31    Console.WriteLine("DocumentID: " + xmp["xmpMM:DocumentID"].ToStringValue());

Consulte la extracción de metadatos XMP en Java y C++.

Evalúe los metadatos XMP trabajando en línea en nuestra aplicación Metadatos.

Puede descargar ejemplos y archivos de datos desde GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.