Quick Start Guide

This guide provides a quick overview of how to set up and start using GroupDocs.Signature for Python via .NET. This library enables developers to sing documents various file formats (e.g., DOCX, PDF, PNG) with minimal configuration.

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

Activate a virtual environment:

.venv\Scripts\activate
source .venv/bin/activate

Install groupdocs-signature-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-signature-net
python3 -m pip install groupdocs-signature-net

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

Successfully installed groupdocs-signature-net-*

Example “Hello, world!”

To quickly test the library, let’s sing a PDF file with text signature. You can also download the app that we’re going to buid here.

import groupdocs.signature as gs 
import groupdocs.signature.options as gso 
import sys 
import os

def sign_pdf_with_text_signature():
   
    license = gs.License()
    license.set_license("./GroupDocs.Signature.PythonViaNET.lic")
    
    # The path to the file.
    sample_pdf = "./sample.pdf"

    file_name = os.path.basename("./signed_sample_pdf")

    # The path to the output directory.
    output_directory = "./out"

    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    output_file_path = os.path.join(output_directory, file_name)

    # Sign document with text signature.
    with gs.Signature(sample_pdf) as signature:
        text_sign_options = gso.TextSignOptions("Hello world!")
        signature.sign(output_file_path, text_sign_options)

    print(f"\nSource document signed successfully.\nFile saved at {output_file_path}")

if __name__ == "__main__":
    sign_pdf_with_text_signature()

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

signed_sample.pdf is expected output PDF file. Click here to download it.

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

πŸ“‚ demo-app
 β”œβ”€β”€hello_world.py
 β”œβ”€β”€sample.pdf
 └──GroupDocs.Signature.PythonViaNET.lic (Optionally)

Run the App

py hello_world.py
python3 hello_world.py

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

Explanation

  • gs.License(): Creates a license object for the GroupDocs.Signature library.
  • license.set_license("./GroupDocs.Signature.PythonViaNET.lic"): Applies the license to avoid evaluation limitations.
  • sample_pdf = "./sample.pdf": Defines the path to the input PDF document.
  • output_directory = "./out": Specifies the directory where the signed file will be saved.
  • os.makedirs(output_directory): Creates the output directory if it doesn’t exist.
  • gs.Signature(sample_pdf): Loads the input PDF file for signing.
  • gso.TextSignOptions("Hello world!"): Creates text signature options with the specified signature text.
  • signature.sign(output_file_path, text_sign_options): Applies the text signature and saves the signed PDF to the output path.
  • print(...): Prints a confirmation message with the path to the signed document.

Next Steps

After completing the basics, explore additional resources to enhance your usage: