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_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 // Change named value "stDim:unit" in "xmpTPg:MaxPageSize" structure. 24 xmp->SetNamedValue(u"xmpTPg:MaxPageSize", u"stDim:unit", System::MakeObject<XmpValue>(u"Inches")); 25 26 // Add named value "stDim:newKey" in "xmpTPg:MaxPageSize" structure. 27 xmp->SetNamedValue(u"xmpTPg:MaxPageSize", u"stDim:newKey", System::MakeObject<XmpValue>(u"NewValue")); 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"change_named_value_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 からダウンロードできます。