GetFormattedText

GetFormattedText(FormattedTextOptions)

ドキュメントから書式設定されたテキストを抽出します。

public TextReader GetFormattedText(FormattedTextOptions options)
パラメータ タイプ 説明
options FormattedTextOptions フォーマットされたテキスト抽出オプション。

戻り値

のインスタンスTextReader抽出されたテキストを持つクラス; ヌルフォーマットされたテキストの抽出がサポートされていない場合.

備考

もっと詳しく知る:

次の例は、ドキュメント テキストを HTML テキストとして抽出する方法を示しています。

// Parser クラスのインスタンスを作成します
using (Parser parser = new Parser(filePath))
{
    // 書式設定されたテキストをリーダーに抽出します
    using (TextReader reader = parser.GetFormattedText(new FormattedTextOptions(FormattedTextMode.Html)))
    {
        // ドキュメントから書式設定されたテキストを出力します
        // フォーマットされたテキストの抽出がサポートされていない場合、リーダーは null です
        Console.WriteLine(reader == null ? "Formatted text extraction isn't suppported" : reader.ReadToEnd());
    }
}

関連項目


GetFormattedText(int, FormattedTextOptions)

ドキュメント ページから書式設定されたテキストを抽出します。

public TextReader GetFormattedText(int pageIndex, FormattedTextOptions options)
パラメータ タイプ 説明
pageIndex Int32 ゼロベースのページ インデックス。
options FormattedTextOptions フォーマットされたテキスト抽出オプション。

戻り値

のインスタンスTextReader抽出されたテキストを持つクラス。 ヌル書式付きテキスト ページの抽出がサポートされていない場合.

備考

もっと詳しく知る:

次の例は、ドキュメント ページのテキストを Markdown テキストとして抽出する方法を示しています。

// Parser クラスのインスタンスを作成します
using (Parser parser = new Parser(filePath))
{
    // ドキュメントが書式設定されたテキストの抽出をサポートしているかどうかを確認します
    if (!parser.Features.FormattedText)
    {
        Console.WriteLine("Document isn't supports formatted text extraction.");
        return;
    }
    
    // ドキュメント情報を取得する
    IDocumentInfo documentInfo = parser.GetDocumentInfo();
    // ドキュメントにページがあるかどうかを確認します
    if (documentInfo.PageCount == 0)
    {
        Console.WriteLine("Document hasn't pages.");
        return;
    }
    
    // ページを繰り返す
    for (int p = 0; p<documentInfo.PageCount; p++)
    {
        // ページ番号を出力 
        Console.WriteLine(string.Format("Page {0}/{1}", p + 1, documentInfo.PageCount));
        // 書式設定されたテキストをリーダーに抽出します
        using (TextReader reader = parser.GetFormattedText(p, new FormattedTextOptions(FormattedTextMode.Markdown)))
        {
            // ドキュメントから書式設定されたテキストを出力します
            // 書式付きテキスト抽出機能のサポートを以前に確認したため、null チェックは無視します
            Console.WriteLine(reader.ReadToEnd());
        }
    }
}

関連項目