更改 EPS|C++ 的 XMP 元数据中的命名值

要更改 EPS 文件的 XMP 元数据中的命名值,需要执行以下步骤:

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


以下代码片段显示如何在 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"add_named_value_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        //Change XMP metadata values
22        
23        // Add named value to "xmpTPg:MaxPageSize" structure.
24        xmp->AddNamedValue(u"xmpTPg:MaxPageSize", u"stDim:newKey", System::MakeObject<XmpValue>(u"NewValue"));
25        
26        // Save EPS file with changed XMP metadata
27        
28        // Create ouput stream
29        System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"add_named_value_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
30        
31        // Save EPS file
32        
33        {
34            auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]()
35            {
36                outPsStream->Close();
37            });
38            
39            try
40            {
41                document->Save(outPsStream);
42                outPsStream->Flush();
43            }
44            catch (...)
45            {
46                throw;
47            }
48        }
49        
50    }
51    catch (...)
52    {
53        throw;
54    }
55}

请参阅 Java.NET 中 XMP 元数据中命名值的更改。

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.