在 EPS 的 XMP 元数据中添加数组项 | C++
为了在 EPS 文件的 XMP 元数据中添加数组项,需要执行以下步骤:
- 初始化输入 EPS 文件的输入流。
- 从先前创建的输入流创建 PsDocument 实例。
- 从 PsDocument 获取 XmpMetadata 实例。如果给定的 EPS 文件不包含 XMP 元数据,则将创建新的实例,并使用 PS 元数据注释中的值填充该实例并返回给您。
- 现在,您可以向数组元数据字段添加项。
- 初始化输出 EPS 文件的输出流。
- 保存包含更改后的 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_simple_props_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 one more title. I will be added at the end of array by default.
24 xmp->AddArrayItem(u"dc:title", System::MakeObject<XmpValue>(u"NewTitle"));
25
26 // Add one more creator. It will be added in the array by an index (0).
27 xmp->AddArrayItem(u"dc:creator", 0, System::MakeObject<XmpValue>(u"NewCreator"));
28
29 // Save EPS file with changed XMP metadata
30
31 // Create ouput stream
32 System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"add_array_items_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
33
34 // Save EPS file
35
36 {
37 auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]()
38 {
39 outPsStream->Close();
40 });
41
42 try
43 {
44 document->Save(outPsStream);
45 outPsStream->Flush();
46 }
47 catch (...)
48 {
49 throw;
50 }
51 }
52
53 }
54 catch (...)
55 {
56 throw;
57 }
58}
您可以从 GitHub下载示例和数据文件。