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.
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
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-mpipinstallgroupdocs-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.
importgroupdocs.signatureasgsimportgroupdocs.signature.optionsasgsoimportsysimportosdefsign_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"ifnotos.path.exists(output_directory):os.makedirs(output_directory)output_file_path=os.path.join(output_directory,file_name)# Sign document with text signature.withgs.Signature(sample_pdf)assignature: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: