How to Run Examples

The complete project GroupDocs.Parser Examples with code examples and sample files is hosted on GitHub.

Run examples using PyPI

To get started make sure that Python is installed. The package supports Python 3.5-3.14; the examples use f-strings and need 3.6 or higher.

  1. Clone repository with examples:

    git clone https://github.com/groupdocs-parser/GroupDocs.Parser-for-Python-via-.NET.git
    
  2. Navigate to the Examples folder:

    cd ./GroupDocs.Parser-for-Python-via-.NET/Examples
    
  3. Install the necessary packages:

    pip install -r requirements.txt
    
  4. Run the examples:

    python run_all_examples.py
    

Each example is a separate script in a folder that mirrors this documentation, next to its input files, so you can also run one on its own from its folder, for example cd developer-guide/basic-usage/extract-text-from-documents and then python example-1.py. Set GROUPDOCS_LIC_PATH to your licence file first to run them without the evaluation limits.

Build project from scratch

If you prefer to create a project from scratch, follow these steps:

Step 1: Install GroupDocs.Parser

Install GroupDocs.Parser for Python via .NET using pip:

pip install groupdocs-parser-net

Step 2: Create a Python Script

Create a new Python file (e.g., example.py) and add the following code:

from groupdocs.parser import Parser

# Create an instance of Parser class
with Parser("./sample.docx") 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.docx

Step 3: Run the Script

Execute your Python script:

python example.py

The extracted text will appear in the console.

Common Examples

Extract Text from PDF

from groupdocs.parser import Parser

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

Extract Metadata

from groupdocs.parser import Parser

with Parser("./sample.docx") as parser:
    metadata = parser.get_metadata()
    if metadata is not None:
        for item in metadata:
            print(f"{item.name}: {item.value}")

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

Extract Images

from groupdocs.parser import Parser

with Parser("./sample.pdf") as parser:
    images = parser.get_images()
    if images is not None:
        print(f"Found {len(images)} images")
        for i, image in enumerate(images, start=1):
            # 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

Contribute

If you like to add or improve an example, we encourage you to contribute to the project. All examples in this repository are open-source and can be freely used in your own applications.

To contribute, you can fork the repository, edit the source code and create a pull request. We will review the changes and include them in the repository if found helpful.

Close
Loading

Analyzing your prompt, please hold on...

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