XMP EPS メタデータの操作

C# API を使用して EPS ファイルのメタデータを追加、編集、取得する

 

XMP メタデータは、ファイルを特徴付ける一連のプロパティであり、XML 形式で表されます。これには、ファイルの内容を説明するファイル情報と、そのファイルを他のファイルと区別できるようにする識別情報が含まれています。また、作成と変更に関するデータ、ファイルの作成、変更、アップロードに何らかの形で関与したユーザー、およびファイルの変換履歴も保存されます。

Aspose.Page API ソリューションは、他のさまざまな機能の中でも、EPS ファイルの XMP メタデータの操作を可能にします。ここでは、それらを追加、編集、取得する方法を説明する情報を見つけることができます。 XMP メタデータ の操作方法の例をご覧ください。また、当社の XMP Metadata Editor ウェブアプリを試して、機能がどのように使用されるかを確認してください。

C# で EPS ファイルに XMP メタデータを追加する手順

  1. ドキュメント ディレクトリへのパスを設定します。
  2. EPS ファイル入力ストリームを初期化します。
  3. PsDocument クラス を使用してストリームから PS ファイルを作成します。
  4. XMP メタデータを取得するには、 GetXmpMetadata() メソッドを使用します。
  5. Save() メソッドを使用して、変更された EPS ドキュメントを保存します。

XMP メタデータ追加用の C# コード

    using Aspose.Page.EPS;
    using Aspose.Page.EPS.Device;
    using Aspose.Page.EPS.XMP;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize an EPS file input stream
    System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "add_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
    // Create the PsDocument instance from the stream
    PsDocument document = new PsDocument(psStream);            

    try
    {
        // Get XMP metadata. If the EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
        XmpMetadata xmp = document.GetXmpMetadata();

        // Check metadata values extracted from PS metadata comments and set up in new XMP metadata

        // Get the "CreatorTool" value
        if (xmp.Contains("xmp:CreatorTool"))
        Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());

        // Get the "CreateDate" value
        if (xmp.Contains("xmp:CreateDate"))
            Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());

        // Get the "format" value
        if (xmp.Contains("dc:format"))
            Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());

        // Get the "title" value
        if (xmp.Contains("dc:title"))
            Console.WriteLine("Title: " + xmp["dc:title"].ToArray()[0].ToStringValue());

        // Get the "creator" value
        if (xmp.Contains("dc:creator"))
            Console.WriteLine("Creator: " + xmp["dc:creator"].ToArray()[0].ToStringValue());

        // Get the "MetadataDate" value
        if (xmp.Contains("xmp:MetadataDate"))
            Console.WriteLine("MetadataDate: " + xmp["xmp:MetadataDate"].ToStringValue());

        // Save the EPS file with new XMP metadata

        // Create the ouput stream
        using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "add_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
        {
            // Save the EPS file
            document.Save(outPsStream);
        }

    }
    finally
    {
        psStream.Close();
    }

C# で EPS ファイルの XMP メタデータを編集する手順

  1. ドキュメント ディレクトリへのパスを設定します。
  2. EPS ファイル入力ストリームを初期化します。
  3. ストリームから PsDocument クラス を使用して PS ファイルを作成します。
  4. XMP メタデータを取得するには、GetXmpMetadata() メソッドを使用します。
  5. XMP メタデータ値を変更するには、 SetArrayItem() メソッドを使用します。
  6. 変更された EPS ファイルを保存します。

XMP メタデータ変更用の C# コード

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize an EPS file input stream
    System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
    // Create a PsDocument instance from the stream
    PsDocument document = new PsDocument(psStream);            

    try
    {
        // Get XMP metadata. If the EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
        XmpMetadata xmp = document.GetXmpMetadata();

        //Change the XMP metadata values

        // Change the title item at index 0
        xmp.SetArrayItem("dc:title", 0, new XmpValue("NewTitle"));

        // Change the creator item at index 0
        xmp.SetArrayItem("dc:creator", 0, new XmpValue("NewCreator"));

        // Save the EPS file with the changed XMP metadata

        // Create an ouput stream
        using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "change_array_items_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
        {
            // Save the EPS file
            document.Save(outPsStream);
        }

    }
    finally
    {
        psStream.Close();
    }

C# で EPS ファイルの XMP メタデータを取得する手順

  1. ドキュメント ディレクトリへのパスを設定します。
  2. EPS ファイル入力ストリームを初期化します。
  3. ストリームから PsDocument クラス を使用して PS ファイルを作成します。
  4. GetXmpMetadata() メソッドを使用して XMP メタデータを取得します。

XMP メタデータ取得用の C# コード

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
    // Initialize an EPS file input stream
    System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "get_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
    // Create a PsDocument instance from the stream
    PsDocument document = new PsDocument(psStream);            

    try
    {
        // Get XMP metadata. If the EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
        XmpMetadata xmp = document.GetXmpMetadata();

        // Get the "CreatorTool" value
        if (xmp.Contains("xmp:CreatorTool"))
            Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
                
        // Get the "CreateDate" value
        if (xmp.Contains("xmp:CreateDate"))
            Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());

        // Get a width of a thumbnail image if exists
        if (xmp.Contains("xmp:Thumbnails") && xmp["xmp:Thumbnails"].IsArray)
        {
            XmpValue val = xmp["xmp:Thumbnails"].ToArray()[0];
            if (val.IsNamedValues && val.ToDictionary().ContainsKey("xmpGImg:width"))
                Console.WriteLine("Thumbnail Width: " + val.ToDictionary()["xmpGImg:width"].ToInteger());
        }

        // Get the "Format" value
        if (xmp.Contains("dc:format"))
            Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());

        // Get the "DocumentID" value
        if (xmp.Contains("xmpMM:DocumentID"))
            Console.WriteLine("DocumentID: " + xmp["xmpMM:DocumentID"].ToStringValue());

    }
    finally
    {
        psStream.Close();
    }



よくある質問

1. XMPメタデータとは何ですか?

XMP は Extensible Metadata Platform の略語で、メディア ファイルにメタデータ プロパティを埋め込むための標準です。

2. XMPにはどのような情報が含まれていますか?

バージョン、タイトル、説明、キーワード、ファイルを一意に識別できる識別子、履歴情報など、アプリケーションの作成者、編集者、作成者に関する情報が含まれています。

3. XMP メタデータを EPS ファイルに追加するにはどうすればよいですか?

ドキュメント ディレクトリへのパスを設定し、ストリームから EPS ファイルを作成します。 XMP メタデータを追加するには、XmpMetadata クラスの Add() メソッドを使用します。

EPS EPS ファイル形式とは

EPS (Encapsulated PostScript) は、1 ページのレイアウトを記述する PostScript ベースのフォーマットです。ベクター画像やベクター‑ラスタ混合画像に最適です。インポート後は編集できないため、SVG や PDF など編集可能な形式に変換して使用します。