Alterar valor nomeado nos metadados XMP de EPS|C++
Para alterar o valor nomeado nos metadados XMP do ficheiro EPS, é necessário seguir vários passos:
- Inicializar um fluxo de entrada para o ficheiro EPS de entrada.
- Criar uma instância de PsDocument a partir do fluxo de entrada criado anteriormente.
- 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 dos metadados PS e devolvido a si.
- Agora pode alterar o valor nomeado dos campos de metadados da estrutura.
- Inicializar um fluxo de saída para o ficheiro EPS de saída.
- Guardar o ficheiro EPS com os metadados XMP alterados.
O seguinte excerto de código mostra como alterar o valor nomeado nos metadados XMP no 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"add_named_value_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 //Change XMP metadata values 22 23 // Add named value to "xmpTPg:MaxPageSize" structure. 24 xmp->AddNamedValue(u"xmpTPg:MaxPageSize", u"stDim:newKey", System::MakeObject<XmpValue>(u"NewValue")); 25 26 // Save EPS file with changed XMP metadata 27 28 // Create ouput stream 29 System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"add_named_value_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write); 30 31 // Save EPS file 32 33 { 34 auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]() 35 { 36 outPsStream->Close(); 37 }); 38 39 try 40 { 41 document->Save(outPsStream); 42 outPsStream->Flush(); 43 } 44 catch (...) 45 { 46 throw; 47 } 48 } 49 50 } 51 catch (...) 52 { 53 throw; 54 } 55}Pode descarregar exemplos e ficheiros de dados do GitHub.