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
fromgroupdocs.parserimportParserfromgroupdocs.parser.optionsimportSearchOptionswithParser("sample.pdf")asparser:# match_case, match_whole_word, use_regular_expression, search_by_pagesoptions=SearchOptions(False,False,False,True)results=parser.search("harvest",options)ifresultsisNone:print("Search isn't supported for this format.")else:forresultinresults: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
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.
fromgroupdocs.parserimportParserfromgroupdocs.parser.optionsimportFormattedTextOptions,FormattedTextModewithParser("sample.pptx")asparser:# 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()ifreaderisnotNoneelse"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]