This guide provides a quick overview of how to set up and start using GroupDocs.Editor for Python via .NET. The library loads a document, converts it to editable HTML/CSS, lets you edit that markup, and saves it back to the original format — or to a different one.
For best practices, use a virtual environment to manage dependencies in Python applications. Learn more about virtual environment at Create and Use Virtual Environments documentation topic.
Create and Activate a Virtual Environment
Create a virtual environment:
py-mvenv.venv
python3 -m venv .venv
python3 -m venv .venv
Activate a virtual environment:
.venv\Scripts\activate
source .venv/bin/activate
source .venv/bin/activate
Install groupdocs-editor-net Package
After activating the virtual environment, run the following command in your terminal to install the latest version of the package:
py-mpipinstallgroupdocs-editor-net
python3 -m pip install groupdocs-editor-net
python3 -m pip install groupdocs-editor-net
Ensure the package is installed successfully. You should see the message
Successfully installed groupdocs-editor-net-*
Example 1: Edit a Word document
To quickly test the library, let’s load a DOCX file, edit its HTML, and save it back to DOCX.
importosfromgroupdocs.editorimportEditor,EditableDocument,Licensefromgroupdocs.editor.formatsimportWordProcessingFormatsfromgroupdocs.editor.optionsimportWordProcessingSaveOptionsdefedit_word_document():# Optionally set a licenselicense_path=os.path.abspath("./GroupDocs.Editor.lic")ifos.path.exists(license_path):License().set_license(license_path)# Load the documentwithEditor("./sample-document.docx")aseditor:# Convert the document to editable HTMLeditable=editor.edit()html=editable.get_embedded_html()# Edit the HTML markup (rename the document title)edited_html=html.replace("Title of the document","Title of the edited document")# Build an editable document from the modified markup and save it back to DOCXafter_edit=EditableDocument.from_markup(edited_html)editor.save(after_edit,"./edited-document.docx",WordProcessingSaveOptions(WordProcessingFormats.DOCX))if__name__=="__main__":edit_word_document()
sample-document.docx is the sample file used in this example. Click here to download it.
After running the app you can deactivate virtual environment by executing deactivate or closing your shell.
Explanation
Editor("./sample-document.docx"): Loads the document into the editor.
editor.edit(): Converts the document to an EditableDocument and get_embedded_html() returns a self-contained HTML string.
EditableDocument.from_markup(edited_html): Wraps the modified markup back into an editable document.
editor.save(..., WordProcessingSaveOptions(WordProcessingFormats.DOCX)): Saves the edited document back to DOCX.
Example 2: Convert a document to another format
In this example we convert a DOCX file to PDF. GroupDocs.Editor converts through its HTML intermediate — saving an EditableDocument with a different *SaveOptions produces a different output format.
importosfromgroupdocs.editorimportEditor,Licensefromgroupdocs.editor.optionsimportPdfSaveOptionsdefconvert_word_to_pdf():# Optionally set a licenselicense_path=os.path.abspath("./GroupDocs.Editor.lic")ifos.path.exists(license_path):License().set_license(license_path)# Load the documentwithEditor("./sample-document.docx")aseditor:# Convert the document to editable HTMLeditable=editor.edit()# Save the editable document as PDFeditor.save(editable,"./sample-document.pdf",PdfSaveOptions())if__name__=="__main__":convert_word_to_pdf()
sample-document.docx is the sample file used in this example. Click here to download it.
editor.edit(): Converts the source document to an EditableDocument.
PdfSaveOptions(): Selects PDF as the output format.
editor.save(editable, "./sample-document.pdf", PdfSaveOptions()): Writes the document out as PDF through the HTML intermediate.
Example 3: Read document information
Sometimes you only need a document’s metadata. get_document_info() returns format, page count, size, and encryption status without a full edit pass.
importosfromgroupdocs.editorimportEditor,Licensedefget_document_info():# Optionally set a licenselicense_path=os.path.abspath("./GroupDocs.Editor.lic")ifos.path.exists(license_path):License().set_license(license_path)# Load the document and read its metadatawithEditor("./sample-document.docx")aseditor:info=editor.get_document_info()print("Format:",info.format.name)print("Extension:",info.format.extension)print("Pages:",info.page_count)print("Size, bytes:",info.size)print("Encrypted:",info.is_encrypted)if__name__=="__main__":get_document_info()
sample-document.docx is the sample file used in this example. Click here to download it.
Format: Office Open XML WordProcessingML Macro-Free Document (DOCX)
Extension: docx
Pages: 3
Size, bytes: 49455
Encrypted: False
editor.get_document_info(): Returns a lightweight view of the document’s metadata.
The view supports snake_case attribute access (info.page_count, info.format.name) as well as dict-style access for the underlying PascalCase keys (info["PageCount"]).
Next Steps
After completing the basics, explore additional resources to enhance your usage: