This guide gives a quick overview of how to set up and start using GroupDocs.Signature for Python via .NET. The library adds, finds, verifies, updates and removes electronic signatures in PDF, Word, Excel, PowerPoint, OpenDocument and image files with a few lines of code.
Prerequisites
To proceed, make sure you have:
A configured environment as described in the System Requirements topic. On Linux and macOS this includes a few system packages.
Optionally, a Temporary License to test all the product features. Without a license the library works in evaluation mode: it processes documents of up to two pages and adds an evaluation line to every page it signs. See Licensing.
See Installation for pinning a version and for installing without access to PyPI.
Example 1: Sign a PDF with a Text Signature
Open a document, describe the signature with TextSignOptions, and save the signed copy.
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportTextSignOptionsdefsign_pdf_with_text_signature():# Open the document; the with-block releases the file when it endswithSignature("sample.pdf")assignature:# A text signature 100 pixels from the left and top edges of the first pageoptions=TextSignOptions("John Smith")options.left=100options.top=100# Sign and save the result to a new file; the source stays unchangedresult=signature.sign("signed_sample.pdf",options)print(f"Signatures added: {len(result.succeeded)}")if__name__=="__main__":sign_pdf_with_text_signature()
sample.pdf is the sample file used in this example. Click here to download it.
Find the signatures a document already carries. search takes a list of search options, one per signature type to look for, and returns them in result.signatures.
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportTextSearchOptionsdefsearch_document_for_signatures():withSignature("signed.pdf")assignature:# Look for text signatures on every pageresult=signature.search([TextSearchOptions()])forfoundinresult.signatures:print(f"Text signature '{found.text}' on page {found.page_number}")if__name__=="__main__":search_document_for_signatures()
signed.pdf is the sample file used in this example. Click here to download it.
Check that a document carries the signature you expect. Verification succeeds when a text signature with exactly this text is found.
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportTextVerifyOptionsdefverify_text_signature():withSignature("signed.pdf")assignature:options=TextVerifyOptions("John Smith")result=signature.verify(options)print(f"Document is signed by John Smith: {result.is_valid}")if__name__=="__main__":verify_text_signature()
signed.pdf is the sample file used in this example. Click here to download it.
When you are done, deactivate the virtual environment by running deactivate or closing your shell.
Apply a License
Set the GROUPDOCS_LIC_PATH environment variable to the full path of your license file, and the license is applied automatically when groupdocs.signature is imported. No code is needed. Alternatively, apply it in code once, before any other call: