Ajouter des métadonnées XMP au fichier EPS en utilisant C++

Afin d’ajouter des métadonnées XMP au 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.
  5. Initialisez un flux de sortie pour le fichier EPS de sortie.
  6. Enregistrez le fichier EPS avec les nouvelles métadonnées XMP.


L’extrait de code suivant montre comment ajouter des métadonnées XMP au 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"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}

Voir l’ajout de 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.