Ottieni metadati XMP da file EPS usando C++

Per estrarre i metadati XMP da 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.


Il seguente frammento di codice mostra come estrarre i metadati XMP da 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"get_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        // Get "CreatorTool" value
22        if (xmp->Contains(u"xmp:CreatorTool"))
23        {
24            System::Console::WriteLine(System::String(u"CreatorTool: ") + xmp->idx_get(u"xmp:CreatorTool")->ToStringValue());
25        }
26        
27        // Get "CreateDate" value
28        if (xmp->Contains(u"xmp:CreateDate"))
29        {
30            System::Console::WriteLine(System::String(u"CreateDate: ") + xmp->idx_get(u"xmp:CreateDate")->ToStringValue());
31        }
32        
33        // Get a width of a thumbnail image if exists
34        if (xmp->Contains(u"xmp:Thumbnails") && xmp->idx_get(u"xmp:Thumbnails")->get_IsArray())
35        {
36            System::SharedPtr<XmpValue> val = xmp->idx_get(u"xmp:Thumbnails")->ToArray()->idx_get(0);
37            if (val->get_IsNamedValues() && val->ToDictionary()->ContainsKey(u"xmpGImg:width"))
38            {
39                System::Console::WriteLine(System::String(u"Thumbnail Width: ") + val->ToDictionary()->idx_get(u"xmpGImg:width")->ToInteger());
40            }
41        }
42        
43        // Get "format" value
44        if (xmp->Contains(u"dc:format"))
45        {
46            System::Console::WriteLine(System::String(u"Format: ") + xmp->idx_get(u"dc:format")->ToStringValue());
47        }
48        
49        // Get "DocumentID" value
50        if (xmp->Contains(u"xmpMM:DocumentID"))
51        {
52            System::Console::WriteLine(System::String(u"DocumentID: ") + xmp->idx_get(u"xmpMM:DocumentID")->ToStringValue());
53        }
54        
55    }
56    catch (...)
57    {
58        throw;
59    }
60}

Vedere l’estrazione dei 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.