Alterar valores simples em metadados XMP EPS | C++

Para alterar valores simples nos 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 do PsDocument. Se o ficheiro EPS fornecido não contiver metadados XMP, um novo será criado, preenchido com os valores dos comentários dos metadados PS e devolvido a si.
  4. Agora pode alterar os valores dos campos de metadados.
  5. Inicializar um fluxo de saída para o ficheiro EPS de saída.
  6. Guardar o ficheiro EPS com os metadados XMP alterados.


O seguinte excerto de código mostra como alterar valores simples nos metadados XMP do 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        //Change XMP metadata values
22        
23        
24        // Change ModifyDate value
25        System::DateTime now = System::DateTime::get_UtcNow();
26        xmp->idx_set(u"xmp:ModifyDate", XmpValue::to_XmpValue(now));
27        
28        // Change Creator value
29        System::SharedPtr<XmpValue> value = System::MakeObject<XmpValue>(u"Aspose.Page");
30        xmp->Add(u"dc:creator", value);
31        
32        // Change Title value
33        value = System::MakeObject<XmpValue>(u"(PAGEJAVA-29.eps)");
34        xmp->Add(u"dc:title", value);
35        
36        // Save EPS file with changed XMP metadata
37        
38        // Create ouput stream
39        System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"change_values_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
40        
41        // Save EPS file
42        
43        {
44            auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]()
45            {
46                outPsStream->Close();
47            });
48            
49            try
50            {
51                document->Save(outPsStream);
52                outPsStream->Flush();
53            }
54            catch (...)
55            {
56                throw;
57            }
58        }
59        
60    }
61    catch (...)
62    {
63        throw;
64    }
65}

Veja como alterar valores simples nos 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.