操作 XMP 元数据

轻松添加、编辑和检索 EPS 文件中的元数据,让您完全掌控文档信息。使用 Aspose.Page Solution for C++ 将 EPS 文件的内容提升到新水平!

 

XMP 元数据是用于描述文件的属性集合。它以 XML 格式书写。元数据包括文件内容信息、区别于其他文件的标识详情,以及与文件创建、修改和上传历史相关的其他数据。此外,它还记录参与文件创建、编辑和上传的用户详情。

使用我们的 C++ API 解决方案释放您的 EPS 文件的潜力!与 XMP 元数据无缝集成,让您完全掌控 EPS 文档。无论是管理数字资产、增强版权信息,还是优化创意工作流程,我们的 API 都能简化流程,确保精度和效率。提升您的元数据处理能力,深入了解您的 EPS 文件。使用我们的 C++ API 解决方案体验与 XMP 元数据的无缝集成。立即购买解决方案,或者获取免费试用版,以探索从 EPS 文件中添加、编辑和检索元数据的功能!有关使用 XMP 元数据的更多信息和示例,请访问 GitHub 上的 Aspose.Page API 文档。还可以试用我们的 XMP 元数据编辑器 Web 应用,了解该功能的使用方式。

要运行代码示例,您需要:

  • Aspose.Page for C++ API,这是一款功能丰富、功能强大且易于使用的 C++ 平台文档操作和转换 API。

  • 您可以直接下载其最新版本,只需打开 NuGet 包管理器,搜索 Aspose.Page.Cpp 并安装。您也可以在包管理器控制台中使用以下命令。

Package Manager Console Command

    PM> Install-Package Aspose.Page.Cpp

使用 C++ 将 XMP 元数据添加到 EPS 文件

要将 XMP 元数据插入 EPS,您需要使用 XmpMetadata 类的实体。请按以下步骤操作:

  1. 设置文档所在目录的路径。
  2. 初始化 EPS 文件的输入流。
  3. 使用 PsDocument 类从输入流创建 PS 文件。
  4. 通过调用 GetXmpMetadata() 方法检索 XMP 元数据。如果 EPS 文件不包含 XMP 元数据,我们将获得一个用 PS 元数据注释中的值填充的新元数据。
  5. 通过调用 Save() 方法保存更改后的 EPS 文档。
添加 XMP 元数据
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize EPS file input stream
    System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir + u"add_input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
    // Create PsDocument instance from stream
    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream);
    
    
    {
        auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream]()
        {
            psStream->Close();
        });
        
        try
        {
            // 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)
            System::SharedPtr<XmpMetadata> xmp = document->GetXmpMetadata();
            
            // Check metadata values extracted from PS metadata comments and set up in new XMP metadata
            
            // Get "CreatorTool" value
            if (xmp->Contains(u"xmp:CreatorTool"))
            {
                System::Console::WriteLine(System::String(u"CreatorTool: ") + xmp->idx_get(u"xmp:CreatorTool")->ToStringValue());
            }
            
            // Get "CreateDate" value
            if (xmp->Contains(u"xmp:CreateDate"))
            {
                System::Console::WriteLine(System::String(u"CreateDate: ") + xmp->idx_get(u"xmp:CreateDate")->ToStringValue());
            }
            
            // Get "format" value
            if (xmp->Contains(u"dc:format"))
            {
                System::Console::WriteLine(System::String(u"Format: ") + xmp->idx_get(u"dc:format")->ToStringValue());
            }
            
            // Get "title" value
            if (xmp->Contains(u"dc:title"))
            {
                System::Console::WriteLine(System::String(u"Title: ") + xmp->idx_get(u"dc:title")->ToArray()->idx_get(0)->ToStringValue());
            }
            
            // Get "creator" value
            if (xmp->Contains(u"dc:creator"))
            {
                System::Console::WriteLine(System::String(u"Creator: ") + xmp->idx_get(u"dc:creator")->ToArray()->idx_get(0)->ToStringValue());
            }
            
            // Get "MetadataDate" value
            if (xmp->Contains(u"xmp:MetadataDate"))
            {
                System::Console::WriteLine(System::String(u"MetadataDate: ") + xmp->idx_get(u"xmp:MetadataDate")->ToStringValue());
            }
            
            // Save EPS file with new XMP metadata
            
            // Create ouput stream
            {
                System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output/" + u"add_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
                // Clearing resources under 'using' statement
                System::Details::DisposeGuard<1> __dispose_guard_1({ outPsStream});
                // ------------------------------------------
                
                try
                {
                    // Save EPS file
                    document->Save(outPsStream);
                }
                catch(...)
                {
                    __dispose_guard_1.SetCurrentException(std::current_exception());
                }
            }
            
        }
        catch (...)
        {
            throw;
        }
    }

使用 C++ 更改 EPS 文件的 XMP 元数据

要向 XMP 元数据添加数组项,您还需要使用相同的实体并执行类似的步骤。附加步骤需要使用 SetArrayItem 或 AddArrayItem() 。

更改 XMP 元数据
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize EPS file input stream
    System::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);
    // Create PsDocument instance from stream
    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream);
    
    
    {
        auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream]()
        {
            psStream->Close();
        });
        
        try
        {
            // 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)
            System::SharedPtr<XmpMetadata> xmp = document->GetXmpMetadata();
            
            //Change XMP metadata values
            
            // Add one more title. I will be added at the end of array by default.
            xmp->AddArrayItem(u"dc:title", System::MakeObject<XmpValue>(u"NewTitle"));
            
            // Add one more creator. It will be added in the array by an index (0).
            xmp->AddArrayItem(u"dc:creator", 0, System::MakeObject<XmpValue>(u"NewCreator"));
            
            // Save EPS file with changed XMP metadata
            
            // Create ouput stream
            {
                System::SharedPtr<System::IO::FileStream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output/" + u"add_array_items_output.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
                // Clearing resources under 'using' statement
                System::Details::DisposeGuard<1> __dispose_guard_1({ outPsStream});
                // ------------------------------------------
                
                try
                {
                    // Save EPS file
                    document->Save(outPsStream);
                }
                catch(...)
                {
                    __dispose_guard_1.SetCurrentException(std::current_exception());
                }
            }
            
        }
        catch (...)
        {
            throw;
        }
    }

EPS 什么是EPS文件格式

EPS(Encapsulated PostScript)是一种基于 PostScript 的单页描述格式,适用于矢量图形和矢量‑光栅混合图像。导入后文件不可编辑,建议转换为可编辑格式(如 SVG 或 PDF)后使用。