XMP EPS メタデータの操作

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

 

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

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

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

  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();
    }

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

  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();
    }

EPS ファイル C# の 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 など編集可能な形式に変換して使用します。