Get XMP metadata from EPS file using C++
In order to extract XMP metadata from 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 view values of metadata fields.
Following code snippet shows how to extract XMP metadata from EPS file in C++:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
2// The path to the documents directory.
3System::String dataDir = RunExamples::GetDataDir_WorkingWithXMPMetadataInEPS();
4// Initialize EPS file input stream
5System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir + u"get_input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
6// Create PsDocument instance from stream
7System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream);
8
9
10{
11 auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream]()
12 {
13 psStream->Close();
14 });
15
16 try
17 {
18 // 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)
19 System::SharedPtr<XmpMetadata> xmp = document->GetXmpMetadata();
20
21 // Get "CreatorTool" value
22 if (xmp->Contains(u"xmp:CreatorTool"))
23 {
24 System::Console::WriteLine(System::String(u"CreatorTool: ") + xmp->idx_get(u"xmp:CreatorTool")->ToStringValue());
25 }
26
27 // Get "CreateDate" value
28 if (xmp->Contains(u"xmp:CreateDate"))
29 {
30 System::Console::WriteLine(System::String(u"CreateDate: ") + xmp->idx_get(u"xmp:CreateDate")->ToStringValue());
31 }
32
33 // Get a width of a thumbnail image if exists
34 if (xmp->Contains(u"xmp:Thumbnails") && xmp->idx_get(u"xmp:Thumbnails")->get_IsArray())
35 {
36 System::SharedPtr<XmpValue> val = xmp->idx_get(u"xmp:Thumbnails")->ToArray()->idx_get(0);
37 if (val->get_IsNamedValues() && val->ToDictionary()->ContainsKey(u"xmpGImg:width"))
38 {
39 System::Console::WriteLine(System::String(u"Thumbnail Width: ") + val->ToDictionary()->idx_get(u"xmpGImg:width")->ToInteger());
40 }
41 }
42
43 // Get "format" value
44 if (xmp->Contains(u"dc:format"))
45 {
46 System::Console::WriteLine(System::String(u"Format: ") + xmp->idx_get(u"dc:format")->ToStringValue());
47 }
48
49 // Get "DocumentID" value
50 if (xmp->Contains(u"xmpMM:DocumentID"))
51 {
52 System::Console::WriteLine(System::String(u"DocumentID: ") + xmp->idx_get(u"xmpMM:DocumentID")->ToStringValue());
53 }
54
55 }
56 catch (...)
57 {
58 throw;
59 }
60}
You can download examples and data files from GitHub.