Aggiungi metadati XMP a un file EPS utilizzando C++

Per aggiungere metadati XMP a 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 visualizzare i valori dei campi dei metadati.
  5. Inizializzare un flusso di output per il file EPS di output.
  6. Salvare il file EPS con i nuovi metadati XMP.


Il seguente frammento di codice mostra come aggiungere metadati XMP a un 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_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        // Check metadata values extracted from PS metadata comments and set up in new XMP metadata
22        
23        // Get "CreatorTool" value
24        if (xmp->Contains(u"xmp:CreatorTool"))
25        {
26            System::Console::WriteLine(System::String(u"CreatorTool: ") + xmp->idx_get(u"xmp:CreatorTool")->ToStringValue());
27        }
28        
29        // Get "CreateDate" value
30        if (xmp->Contains(u"xmp:CreateDate"))
31        {
32            System::Console::WriteLine(System::String(u"CreateDate: ") + xmp->idx_get(u"xmp:CreateDate")->ToStringValue());
33        }
34        
35        // Get "format" value
36        if (xmp->Contains(u"dc:format"))
37        {
38            System::Console::WriteLine(System::String(u"Format: ") + xmp->idx_get(u"dc:format")->ToStringValue());
39        }
40        
41        // Get "title" value
42        if (xmp->Contains(u"dc:title"))
43        {
44            System::Console::WriteLine(System::String(u"Title: ") + xmp->idx_get(u"dc:title")->ToArray()->idx_get(0)->ToStringValue());
45        }
46        
47        // Get "creator" value
48        if (xmp->Contains(u"dc:creator"))
49        {
50            System::Console::WriteLine(System::String(u"Creator: ") + xmp->idx_get(u"dc:creator")->ToArray()->idx_get(0)->ToStringValue());
51        }
52        
53        // Get "MetadataDate" value
54        if (xmp->Contains(u"xmp:MetadataDate"))
55        {
56            System::Console::WriteLine(System::String(u"MetadataDate: ") + xmp->idx_get(u"xmp:MetadataDate")->ToStringValue());
57        }
58        
59        // Save EPS file with new XMP metadata
60        
61        // Create ouput stream
62        System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"add_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
63        
64        // Save EPS file
65        
66        {
67            auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]()
68            {
69                outPsStream->Close();
70            });
71            
72            try
73            {
74                document->Save(outPsStream);
75                outPsStream->Flush();
76            }
77            catch (...)
78            {
79                throw;
80            }
81        }
82        
83    }
84    catch (...)
85    {
86        throw;
87    }
88}

Vedere l’aggiunta di 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.