C# で PDF ファイルを検索する

.NET API 用のサーバーサイド Aspose.PDF を使用したハイパフォーマンスな PDF ドキュメント検索

C# で PDF を検索する方法

PDF ファイルを検索するには、機能豊富で強力で使いやすいドキュメント操作 API である Aspose.PDF API を使用します。NuGet パッケージマネージャーを開き、Aspose.PDF を検索してインストールします。パッケージマネージャーコンソールから次のコマンドを使用することもできます。署名を使用して PDF 文書に署名する場合、基本的にはその内容を「現状のまま」確認します。そのため、後で他の変更を加えると署名が無効になり、文書が変更されたかどうかがわかります。

.NET を使用して PDF ドキュメントを開かずに検索する:

1。検索するテキストをパラメーターとして TextFragmentAbsorber オブジェクトを作成します。 1。抽出されたすべてのテキストフラグメントコレクションを取得します。 1。各フラグメントをループ処理して、すべての情報を取得します。

PDF ファイルを検索

このサンプルコードは、.NET を使用して PDF ファイルを検索する方法を示しています。

    //Search Text from All the Pages of PDF Document
    Document pdfDocument = new Document("SearchAndGetTextFromAll.pdf");

    // Create TextAbsorber object to find all instances of the input search phrase
    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text");

    // Accept the absorber for all the pages
    pdfDocument.Pages.Accept(textFragmentAbsorber);

    // Get the extracted text fragments
    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

    // Loop through the fragments
    foreach (TextFragment textFragment in textFragmentCollection)
    {

        Console.WriteLine("Text : {0} ", textFragment.Text);
        Console.WriteLine("Position : {0} ", textFragment.Position);
        Console.WriteLine("XIndent : {0} ", textFragment.Position.XIndent);
        Console.WriteLine("YIndent : {0} ", textFragment.Position.YIndent);
        Console.WriteLine("Font - Name : {0}", textFragment.TextState.Font.FontName);
        Console.WriteLine("Font - IsAccessible : {0} ", textFragment.TextState.Font.IsAccessible);
        Console.WriteLine("Font - IsEmbedded : {0} ", textFragment.TextState.Font.IsEmbedded);
        Console.WriteLine("Font - IsSubset : {0} ", textFragment.TextState.Font.IsSubset);
        Console.WriteLine("Font Size : {0} ", textFragment.TextState.FontSize);
        Console.WriteLine("Foreground Color : {0} ", textFragment.TextState.ForegroundColor);
    }