EPSファイルのXMPメタデータ内の名前付き値の変更|C++

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.