Aggiungere proprietà nei metadati XMP di un file EPS | C++

Per aggiungere proprietà ai metadati XMP di un file EPS, è necessario eseguire diversi passaggi:

  1. Inizializzare un flusso di input per il file EPS di input.
  2. Creare un’istanza di PsDocument dal flusso di input creato in precedenza.
  3. Ottenere un’istanza di XmpMetadata dal PsDocument. Se il file EPS specificato non contiene metadati XMP, ne verrà creato uno nuovo, compilato con i valori dei commenti dei metadati PS e restituito.
  4. Ora è possibile aggiungere proprietà ai campi dei metadati.
  5. Inizializzare un flusso di output per il file EPS di output.
  6. Salvare il file EPS con i metadati XMP modificati.


Il seguente frammento di codice mostra come aggiungere proprietà nei metadati XMP del file EPS in C++:

 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        
24        System::DateTime now = System::DateTime::get_UtcNow();
25        
26        // Add Integer poperty
27        xmp->Add(u"xmp:Intg1", System::MakeObject<XmpValue>(111));
28        
29        // Add DateTime poperty
30        xmp->Add(u"xmp:Date1", System::MakeObject<XmpValue>(now));
31        
32        // Add Double poperty
33        xmp->Add(u"xmp:Double1", System::MakeObject<XmpValue>(111.11));
34        
35        // Add String poperty
36        xmp->Add(u"xmp:String1", System::MakeObject<XmpValue>(u"ABC"));
37        
38        // Save EPS file with changed XMP metadata
39        
40        // Create ouput stream
41        System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"add_simple_props_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
42        
43        // Save EPS file
44        
45        {
46            auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]()
47            {
48                outPsStream->Close();
49            });
50            
51            try
52            {
53                document->Save(outPsStream);
54                outPsStream->Flush();
55            }
56            catch (...)
57            {
58                throw;
59            }
60        }
61        
62    }
63    catch (...)
64    {
65        throw;
66    }
67}

Vedere l’aggiunta di proprietà nei metadati XMP in Java e .NET.

È possibile scaricare esempi e file di dati da GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.