How to Run Examples

Warning
Before running an example make sure that GroupDocs.Editor for Python via .NET has been installed successfully.

We offer multiple solutions for how you can run GroupDocs.Editor examples, by building your own or by cloning our ready-to-run Python examples repository.

Please choose one from the following list:

Build a project from scratch

  • Create and activate a virtual environment, then install GroupDocs.Editor for Python via .NET following this guide.
py -m venv .venv
.venv\Scripts\activate
py -m pip install groupdocs-editor-net
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install groupdocs-editor-net
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install groupdocs-editor-net
  • Code your first application with GroupDocs.Editor for Python via .NET like this:
import os
from groupdocs.editor import Editor, License
from groupdocs.editor.formats import WordProcessingFormats
from groupdocs.editor.options import WordProcessingEditOptions, WordProcessingSaveOptions

def run_first_example():
    # Optionally set a license
    license_path = os.path.abspath("./GroupDocs.Editor.lic")
    if os.path.exists(license_path):
        License().set_license(license_path)

    # Load the document
    with Editor("./sample-document.docx") as editor:
        # Obtain an editable document from the original DOCX document
        edit_options = WordProcessingEditOptions()
        editable_document = editor.edit(edit_options)

        # Pass the editable document to a WYSIWYG editor and edit there...
        # ...

        # Save the edited document back to a WordProcessing format - DOCX, for example
        save_options = WordProcessingSaveOptions(WordProcessingFormats.DOCX)
        editor.save(editable_document, "./edited-document.docx", save_options)

if __name__ == "__main__":
    run_first_example()

sample-document.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 49 KB)

Download full output

  • Run your script. The edited document will appear in your working directory.
py run_first_example.py
python3 run_first_example.py
python3 run_first_example.py

Run the examples from the repository

The complete examples package of GroupDocs.Editor for Python via .NET is hosted on GitHub. You can either download the ZIP file or clone the repository using your favourite git client.

Clone the repository:

git clone https://github.com/groupdocs-editor/GroupDocs.Editor-for-Python-via-.NET

Create and activate a virtual environment, then install the dependencies listed in requirements.txt:

cd GroupDocs.Editor-for-Python-via-.NET
py -m venv .venv
.venv\Scripts\activate
py -m pip install -r requirements.txt
cd GroupDocs.Editor-for-Python-via-.NET
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
cd GroupDocs.Editor-for-Python-via-.NET
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt

Run all the examples at once:

python run_all_examples.py

Or run an individual example by passing its file name:

python <example>.py

The repository contains all the sample documents and resources used in the examples, so the scripts run out of the box.

Contribute

If you would 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 code, and create a pull request. We will review the changes and include them in the repository if found helpful.