使用 C++ 从 EPS 文件获取 XMP 元数据

为了从 EPS 文件中提取 XMP 元数据,需要执行以下几个步骤:

  1. 为输入的 EPS 文件初始化输入流。
  2. 从先前创建的输入流创建 PsDocument 实例。
  3. 从 PsDocument 获取 XmpMetadata 实例。如果给定的 EPS 文件不包含 XMP 元数据,则将创建新的实例,并使用 PS 元数据注释中的值填充该实例并返回给您。
  4. 现在您可以查看元数据字段的值。


以下代码片段展示了如何在 C++ 中从 EPS 文件中提取 XMP 元数据:

 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}

请参阅在 Java.NET 中提取 XMP 元数据。

您可以从 GitHub下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.