Aggiungi namespace XML nei metadati XMP di EPS | C++
Per aggiungere uno spazio dei nomi XML ai metadati XMP di un file EPS, è necessario eseguire diversi passaggi:
- Inizializzare un flusso di input per il file EPS di input.
- Creare un’istanza di PsDocument dal flusso di input creato in precedenza.
- Ottenere un’istanza di XmpMetadata dal PsDocument. Se il file EPS specificato non contiene metadati XMP, ne verrà creato uno nuovo, compilato con i valori dei commenti dei metadati PS e restituito.
- Ora è possibile aggiungere un nuovo spazio dei nomi XML ai metadati.
- Inizializzare un flusso di output per il file EPS di output.
- Salvare il file EPS con i metadati XMP modificati.
Il seguente frammento di codice mostra come aggiungere lo spazio dei nomi XML nei metadati XMP nel file EPS in 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_simple_props_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 new XML namespace "tmp".
24 xmp->RegisterNamespaceUri(u"tmp", u"http://www.some.org/schema/tmp#");
25
26 // Add new string property in new namespace.
27 xmp->Add(u"tmp:newKey", System::MakeObject<XmpValue>(u"NewValue"));
28
29 // Save EPS file with changed XMP metadata
30
31 // Create ouput stream
32 System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(RunExamples::GetOutDir() + u"add_namespace_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
33
34 // Save EPS file
35
36 {
37 auto __finally_guard_1 = ::System::MakeScopeGuard([&outPsStream]()
38 {
39 outPsStream->Close();
40 });
41
42 try
43 {
44 document->Save(outPsStream);
45 outPsStream->Flush();
46 }
47 catch (...)
48 {
49 throw;
50 }
51 }
52
53 }
54 catch (...)
55 {
56 throw;
57 }
58}
È possibile scaricare esempi e file di dati da GitHub.