Quick Start Guide

This guide provides a quick overview of how to set up and start using GroupDocs.Total for Python via .NET.
It shows three code examples that demonstrate how to use packages included in the suite.

Prerequisites

To proceed, make sure you have:

  1. Configured environment as described in the System Requirements topic.
  2. Optionally you may Get a Temporary License to test all the product features.

Set Up Your Development Environment

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 -3.11 -m venv .venv

Activate a virtual environment:

.venv\Scripts\activate

Install groupdocs-total-net Package

After activating the virtual environment, run the following command in your terminal to install the latest version of the package:

py -m pip install groupdocs-total-net

Ensure the package is installed successfully. You should see the message

Successfully installed groupdocs-total-net-*

Example 1: Convert a document

This example shows how to convert a DOCX document to PDF using GroupDocs.Conversion. You can download the demo app here.

import os
from groupdocs.conversion import License, Converter
from groupdocs.conversion.options.convert import PdfConvertOptions

def convert_docx_to_pdf():
    # Get license file absolute path
    license_path = os.path.abspath("./GroupDocs.Total.lic")

    if os.path.exists(license_path):
        # Create License and set the path
        license = License()
        license.set_license(license_path)

    # Load DOCX file
    with Converter("./business-plan.docx") as converter:
        # Create convert options
        pdf_convert_options = PdfConvertOptions()

        # Convert DOCX to PDF
        converter.convert("./business-plan.pdf", pdf_convert_options)

if __name__ == "__main__":
    convert_docx_to_pdf()

business-plan.docx is sample file used in this example. Click here to download it.

business-plan.pdf is expected output PDF file. Click here to download it.

Your folder tree should look similar to the following directory structure:

📂 demo-app
 ├──convert_docx_to_pdf.py
 ├──business-plan.docx
 └──GroupDocs.Total.lic (Optionally)

Run the App

py convert_docx_to_pdf.py

After running the app you can deactivate virtual environment by executing deactivate or closing your shell.

Explanation

  • Converter("./business-plan.docx"): Initializes the converter with the DOCX file.
  • PdfConvertOptions(): Specifies the output format as PDF.
  • converter.convert("./business-plan.pdf", pdf_convert_options): Converts the DOCX file to PDF and saves it as business-plan.pdf.

Example 2: Remove document metadata

This code example shows how to remove PDF document metadata and save the output to a file with GroupDocs.Metadata. You can download the app that we’re going to buid here.

import os
from groupdocs.metadata import License, Metadata

def remove_pdf_metadata():
    # Get license file absolute path
    license_path = os.path.abspath("./GroupDocs.Total.lic")

    if os.path.exists(license_path):
        # Create License and set the path
        license = License()
        license.set_license(license_path)

    # Load the PDF file
    with Metadata("./business-plan.pdf") as metadata:
      # Remove metadata
      metadata.sanitize()
     
      # Save the file with no metadata
      metadata.save("./no-metadata.pdf")

if __name__ == "__main__":
    remove_pdf_metadata()

business-plan.pdf is sample file used in this example. Click here to download it.

no-metadata.pdf is expected output PDF file without metadata. Click here to download it.

Your folder tree should look similar to the following directory structure:

📂 demo-app
 ├──business-plan.pdf
 ├──remove_pdf_metadata.py
 └──GroupDocs.Total.lic (Optionally)

Run the App

py remove_pdf_metadata.py

After running the app you can deactivate virtual environment by executing deactivate or closing your shell.

Explanation

  • Metadata("./business-plan.pdf"): Initializes metadata object with the source PDF file.
  • metadata.sanitize(): Removes the metadata.
  • metadata.save("./no-metadata.pdf"): Saves the output document without metadata.

Example 3: Convert and remove metadata

This example converts a DOCX file to PDF and removes metadata in a single workflow. You can download the demo app here.

import os
from groupdocs.conversion import License as ConversionLicense, Converter
from groupdocs.conversion.options.convert import PdfConvertOptions
from groupdocs.metadata import License as MetadataLicense, Metadata

def convert_and_remove_metadata():
    # Get license file absolute path
    license_path = os.path.abspath("./GroupDocs.Total.lic")

    if os.path.exists(license_path):
        # License GroupDocs.Conversion
        conversion_license = ConversionLicense()
        conversion_license.set_license(license_path)

        # License GroupDocs.Metadata
        metadata_license = MetadataLicense()
        metadata_license.set_license(license_path)

    # Load DOCX file
    with Converter("./business-plan.docx") as converter:
        # Create convert options
        pdf_convert_options = PdfConvertOptions()

        # Convert DOCX to PDF
        converter.convert("./business-plan.pdf", pdf_convert_options)

    # Load created PDF file
    with Metadata("./business-plan.pdf") as metadata:
      # Remove the metadata
      metadata.sanitize()
     
      # Save the file with no metadata
      metadata.save("./converted-no-metadata.pdf")

if __name__ == "__main__":
    convert_and_remove_metadata()

business-plan.docx is sample file used in this example. Click here to download it.

converted-no-metadata.pdf is output PDF file without metadata. Click here to download the output PDF file.

Your folder tree should look similar to the following directory structure:

📂 demo-app
 ├──business-plan.docx
 ├──convert_and_remove_metadata.py
 └──GroupDocs.Total.lic (Optionally)

Run the App

py convert_and_remove_metadata.py

After running the app you can deactivate virtual environment by executing deactivate or closing your shell.

Explanation

  • Converter("./business-plan.docx"): Initializes the converter with the DOCX file.
  • converter.convert("./business-plan.pdf", pdf_convert_options): Converts the DOCX file to PDF and saves it as business-plan.pdf.
  • Metadata("./business-plan.pdf"): Reads converted PDF file.
  • metadata.sanitize(): Removes the metadata.
  • metadata.save("./converted-no-metadata.pdf"): Saves the output document without metadata.

Learn More