Obtenez les métadonnées XMP à partir du fichier EPS en utilisant C++

Afin d’extraire les métadonnées XMP du fichier EPS, il est nécessaire de suivre plusieurs étapes :

  1. Initialisez un flux d’entrée pour le fichier EPS d’entrée.
  2. Créez une instance de PsDocument à partir du flux d’entrée créé précédemment.
  3. Obtenez une instance de XmpMetadata à partir du PsDocument. Si le fichier EPS donné ne contient pas de métadonnées XMP, le nouveau sera créé, rempli avec les valeurs des commentaires de métadonnées PS et vous sera renvoyé.
  4. Vous pouvez désormais afficher les valeurs des champs de métadonnées.


L’extrait de code suivant montre comment extraire les métadonnées XMP d’un fichier EPS en 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}

Voir l’extraction des métadonnées XMP dans Java et .NET.

Vous pouvez télécharger des exemples et des fichiers de données à partir de GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.