Add XML namespace 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 XML namespace 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 new XML namespace to metadata.
- Initialize an output stream for output EPS file.
- Save EPS file with changed XMP metadata.
The following code snippet shows how to add XML namespace in XMP metadata in EPS file in C#:
1// Add namespace in XMP metadata in EPS document.
2
3// Initialize EPS file input stream
4System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
5
6// Create PsDocument instance from stream
7PsDocument document = new PsDocument(psStream);
8
9string outputFileName = "add_xmp_namespace_out.eps";
10
11try
12{
13 // 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)
14 XmpMetadata xmp = document.GetXmpMetadata();
15
16 //Change XMP metadata values
17
18 // Add new XML namespace "tmp".
19 xmp.RegisterNamespaceUri("tmp", "http://www.some.org/schema/tmp#");
20
21 // Add new string property in new namespace.
22 xmp.Add("tmp:newKey", new XmpValue("NewValue"));
23
24 // Save EPS file with changed XMP metadata
25
26 // Create ouput stream
27 using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
28 {
29 // Save EPS file
30 document.Save(outPsStream);
31 }
32}
33finally
34{
35 psStream.Close();
36}
Evaluate XMP metadata working online on our Metadata application.
You can download examples and data files from GitHub.