Add named value in XMP metadata of EPS | .NET
You can check the quality of Aspose.Page XMP Metadata working with Metadata web app
In order to add named value in XMP metadata of EPS file it is necessary to do several steps:
- Initialize an input stream for input EPS file.
- Create an instance of PsDocument from created earlier input stream.
- Get an instance of XmpMetadata from the PsDocument. If given EPS file doesn’t contain XMP metadata the new one will be created, filled in with values from PS metadata comments and returned to you.
- Now you can add named value to structure metadata fields.
- Initialize an output stream for output EPS file.
- Save EPS file with changed XMP metadata.
Following code snippet shows how to add named value in XMP metadata in EPS file in C#:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2// The path to the documents directory.
3string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
4// Initialize EPS file input stream
5System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "add_named_value_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
6// Create PsDocument instance from stream
7PsDocument document = new PsDocument(psStream);
8
9try
10{
11 // 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)
12 XmpMetadata xmp = document.GetXmpMetadata();
13
14 //Change XMP metadata values
15
16 // Add named value to "xmpTPg:MaxPageSize" structure.
17 xmp.AddNamedValue("xmpTPg:MaxPageSize", "stDim:newKey", new XmpValue("NewValue"));
18
19 // Save EPS file with changed XMP metadata
20
21 // Create ouput stream
22 using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "add_named_value_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
23 {
24 // Save EPS file
25 document.Save(outPsStream);
26 }
27
28}
29finally
30{
31 psStream.Close();
32}
Evaluate XMP metadata working online on our Metadata application.
You can download examples and data files from GitHub.