Working with Text

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Parser MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-parser -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-parser/parser-net-mcp:latest
Folders, licensing and more →

Beyond basic text extraction, you can search inside documents and control how text is returned. This page shows common tasks; consult the API reference for the full list of text-related methods and options.

Search for text

from groupdocs.parser import Parser
from groupdocs.parser.options import SearchOptions

with Parser("sample.pdf") as parser:
    # match_case, match_whole_word, use_regular_expression, search_by_pages
    options = SearchOptions(False, False, False, True)
    results = parser.search("harvest", options)
    if results is None:
        print("Search isn't supported for this format.")
    else:
        for result in results:
            print(f"Found on page {result.page_index + 1}: {result.text}")

The following sample file is used in this example: sample.pdf

Found on page 1: Harvest
Found on page 2: Harvest
Found on page 2: Harvest
Found on page 2: harvest
Found on page 4: harvest
Found on page 4: Harvest

Download full output

Notes

  • parser.search() returns occurrences with matched text; set search_by_pages in SearchOptions to get page indexes.
  • For regex or case-sensitive searches, use search options from groupdocs.parser.options (see the API reference for available parameters).
  • Combine search with get_text() or get_text() per page to extract surrounding content.

Extract formatted or structured text

GroupDocs.Parser can return formatted text (HTML/Markdown/plain) and structured text (headings, lists, tables) when supported by the format.

from groupdocs.parser import Parser
from groupdocs.parser.options import FormattedTextOptions, FormattedTextMode

with Parser("sample.pptx") as parser:
    # Extract formatted text as Markdown (HTML and PLAIN_TEXT modes are also available)
    reader = parser.get_formatted_text(FormattedTextOptions(FormattedTextMode.MARKDOWN))
    print(reader.read_to_end() if reader is not None else "Formatted text isn't available.")

The following sample file is used in this example: sample.pptx

Autumn Harvest 2025

Seasonal lines from Harbor Lane Provisions for grocers, cafes and restaurants.

What is in the range

Autumn Harvest spiced roast from Northwind Coffee Roasters
Apple butter, cranberry relish and fig preserve
Squash soup, muesli and a fruit loaf from local producers

[TRUNCATED]

Download full output

See the API reference for the formatted and structured text methods supported in Python via .NET.