Obter metadados XMP de um ficheiro EPS utilizando C++

Para extrair metadados XMP de um ficheiro EPS, é necessário seguir vários passos:

  1. Inicializar um fluxo de entrada para o ficheiro EPS de entrada.
  2. Criar uma instância de PsDocument a partir do fluxo de entrada criado anteriormente.
  3. Obter uma instância de XmpMetadata a partir do PsDocument. Se o ficheiro EPS fornecido não contiver metadados XMP, será enviado um novo será criado, preenchido com os valores dos comentários de metadados PS e devolvido a si.
  4. Agora pode visualizar os valores dos campos de metadados.


O seguinte excerto de código mostra como extrair metadados XMP de um ficheiro EPS em 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}

Ver extração de metadados XMP em Java e .NET.

Pode descarregar exemplos e ficheiros de dados do GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.