スタンプからテキストを抽出する C#

スタンプ注釈からテキストを抽出する

Aspose.PDF for NET を使用すると、スタンプ注釈からテキストを抽出できます。PDF のスタンプ注釈からテキストを抽出するには、次の手順を使用できます。

  1. Document クラスのオブジェクトを作成します。
  2. ページの注釈リストから目的の Annotation を取得します。
  3. TextAbsorber クラスの新しいオブジェクトを定義します。
  4. TextAbsorber の visit メソッドを使用してテキストを取得します。

次のコードスニペットは、Aspose.PDF.Drawing ライブラリでも動作します。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractText()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Text();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "ExtractStampText.pdf"))
    {
        Aspose.Pdf.Annotations.Annotation item = document.Pages[1].Annotations[1];
        if (item is Aspose.Pdf.Annotations.StampAnnotation annot)
        {
            var absorber = new Aspose.Pdf.Text.TextAbsorber();
            Aspose.Pdf.XForm appearance = annot.Appearance["N"];
            absorber.Visit(appearance);
            Console.WriteLine(absorber.Text);
        }
    }
}