Quick Start Guide

This guide demonstrates the essential steps to get started with GroupDocs.Parser for Python via .NET and perform basic document parsing operations.

Prerequisites

Before you begin, ensure you have:

  • Python 3.5 or higher installed
  • GroupDocs.Parser for Python via .NET installed (see Installation)

Extract Text from a Document

The most common task is extracting text from documents. Here’s how to do it:

from groupdocs.parser import Parser

# Create an instance of Parser class
with Parser("./sample.pdf") as parser:
    # Extract text from the document
    text_reader = parser.get_text()

    if text_reader is None:
        print("Text extraction isn't supported for this format")
    else:
        # Print the extracted text
        print(text_reader.read_to_end())

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

Get Document Information

You can retrieve basic information about a document:

from groupdocs.parser import Parser

# Create an instance of Parser class
with Parser("./sample.pdf") as parser:
    # Get document info
    info = parser.get_document_info()

    print(f"File type: {info.file_type.file_format}")
    print(f"Page count: {info.page_count}")
    print(f"Size: {info.size} bytes")

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

Extract Metadata

Extract metadata properties from documents:

from groupdocs.parser import Parser

# Create an instance of Parser class
with Parser("./sample.pdf") as parser:
    # Extract metadata
    metadata = parser.get_metadata()

    if metadata is None:
        print("Metadata extraction isn't supported for this format")
    else:
        for item in metadata:
            print(f"{item.name}: {item.value}")

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

Extract Images

Extract images from documents:

from groupdocs.parser import Parser

# Create an instance of Parser class
with Parser("./sample.pdf") as parser:
    # Extract images
    images = parser.get_images()

    if images is None:
        print("Image extraction isn't supported for this format")
    else:
        print(f"Found {len(images)} images")
        for i, image in enumerate(images, start=1):
            # Save the image to a file (the extension includes the dot, e.g. ".jpeg")
            image.save(f"image_{i}{image.file_type.extension}")

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

Extract Text from Specific Page

Extract text from a particular page:

from groupdocs.parser import Parser

# Create an instance of Parser class
with Parser("./sample.pdf") as parser:
    # Extract text from the first page (page index is 0-based)
    text_reader = parser.get_text(0)

    if text_reader is None:
        print("Page text extraction isn't supported for this format")
    else:
        print(text_reader.read_to_end())

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

Check Format Support

Before processing a document, you can check if the format is supported:

from groupdocs.parser import Parser
from groupdocs.parser.options import FileType

# Detect the file type
file_info = Parser.get_file_info("./sample.pdf")

if file_info.file_type == FileType.UNKNOWN:
    print("Format is not supported")
else:
    print(f"Format is supported: {file_info.file_type.file_format}")

    # Process the document
    with Parser("./sample.pdf") as parser:
        text_reader = parser.get_text()
        if text_reader is not None:
            print(text_reader.read_to_end())

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

Next Steps

Now that you’ve learned the basics, explore more advanced features:

Additional Resources

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.