This repository demonstrates how to use GroupDocs.Annotation for .NET in Python applications using pythonnet. It provides two distinct implementation approaches to overcome the challenges of loading .NET assemblies with embedded dependencies in Python:
1. Wrapper-Based Approach (add_annotation_wrapper.py)
- Uses a custom C# wrapper library that encapsulates common annotation operations
- Provides simplified static methods for the most common use cases
- Ideal for straightforward annotation tasks with minimal Python/.NET interop complexity
- Best for: Quick prototyping, simple annotation workflows, and users who prefer high-level APIs
2. Manual Type Resolution Approach (add_annotation_manual.py)
- Uses the wrapper only as a dependency resolver for embedded assemblies
- Provides direct access to GroupDocs.Annotation types and methods
- Offers full control over annotation creation and customization
- Best for: Complex annotation scenarios, advanced customization, and developers who need fine-grained control
Both approaches solve the core challenge of loading GroupDocs.Annotation's obfuscated and embedded dependencies in Python environments.
GroupDocs.Annotation for .NET uses obfuscation and embedded dependencies to protect intellectual property. This creates a fundamental challenge when trying to use it directly with pythonnet:
# β This approach WILL NOT work
import os
import sys
# Load coreclr first
from pythonnet import load
load("coreclr")
import clr
# Add folder with the library and dependencies to the system path
dll_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "dlls"))
sys.path.append(dll_dir)
# Add reference to the library
clr.AddReference("GroupDocs.Annotation")
# Import the license class
from GroupDocs.Annotation import License
lic = License()
lic.SetLicense("license.lic")The Problem: GroupDocs.Annotation embeds referenced assemblies (like Aspose.* libraries) directly into the main DLL with obfuscation. When pythonnet tries to load the assembly:
- Type Enumeration Phase: pythonnet attempts to enumerate all public types to build Python module proxies
- Dependency Resolution: During enumeration, the CLR tries to resolve embedded dependencies
- Failure Point: The default .NET assembly resolver cannot extract obfuscated, embedded DLLs from resources
- Result:
ReflectionTypeLoadExceptionis thrown, causing pythonnet to fail creating the Python module
Why This Happens:
- Most obfuscators rely on a bootstrap/resolver that runs in your entry assembly
- Since Python is the host (not a .NET executable), the bootstrap never executes
- The embedded dependencies remain inaccessible to the standard .NET assembly resolver
This repository provides two approaches to solve this challenge:
- Wrapper Library: A C# wrapper that handles dependency resolution and exposes simplified APIs
- Manual Resolution: Direct type resolution using reflection to bypass import issues
Both methods ensure the embedded dependencies are properly resolved before attempting to use GroupDocs.Annotation types.
GroupDocs.Annotation for .NET is a comprehensive document annotation library that allows you to:
- Add annotations to 50+ document formats (PDF, Word, Excel, PowerPoint, images, etc.)
- Create various annotation types: text, area, arrow, point, polyline, watermark, and more
- Customize annotations with colors, fonts, opacity, positioning, and styling
- Export annotated documents to multiple formats while preserving annotations
- Work with existing annotations in documents
- Collaborate on document review and feedback processes
Key Features:
- Support for 50+ document formats
- 10+ annotation types (text, area, arrow, point, polyline, watermark, etc.)
- Cross-platform .NET support
- High-performance rendering
- Flexible licensing options
PythonNet is a package that provides near-seamless integration between Python and the .NET Common Language Runtime (CLR). It allows you to:
- Call .NET assemblies directly from Python code
- Use .NET types and methods as if they were native Python objects
- Access the full .NET ecosystem from Python applications
- Maintain performance with minimal overhead
Key Benefits:
- Direct access to .NET libraries from Python
- No need for separate .NET applications or services
- Maintains Python's simplicity while leveraging .NET's power
- Cross-platform support (Windows, Linux, macOS)
Official Repository: pythonnet/pythonnet
- Operating System: Windows 10/11 (x64), Linux, or macOS
- Python: 3.8+ (recommended: 3.11 or 3.12)
- .NET Runtime: .NET 6.0 or later
- Memory: Minimum 4GB RAM (8GB+ recommended for large documents)
- Disk Space: 500MB+ for dependencies and temporary files
| Python Version | pythonnet Version | .NET Runtime | Supported Target Frameworks | Notes |
|---|---|---|---|---|
| 3.7 β 3.10 | 2.5.x | .NET Framework 4.6.2 β 4.8 | net40, net45, net462, net48 | β
Best for legacy .NET Framework DLLs (e.g., GroupDocs.Annotation net462) Requires 64-bit Python + .NET Framework runtime |
| 3.7 β 3.10 | 2.5.x | Limited .NET Core 3.1 / .NET 5 | Some .NET Standard 2.0 DLLs | Use only if DLL explicitly supports .NET Standard |
| 3.8 β 3.12 | 3.x (β₯3.0.0) | .NET 6 / .NET 7 / .NET 8 | net6.0, net7.0, net8.0, netstandard2.0/2.1 | β
Best for modern .NET builds Requires .NET Desktop Runtime 6+ |
| 3.13+ | 3.x (β₯3.0.3) | .NET 6 / .NET 7 / .NET 8 | Same as above | β
Supported Recommended for latest Python versions |
For this repository, we recommend:
- Python 3.11 with pythonnet 3.0.5
- .NET 6.0 Desktop Runtime
- Windows x64 environment
# Create Python 3.11 virtual environment
py -3.11 -m venv venv311
# Activate virtual environment (Windows)
venv311\Scripts\activate
# Verify Python version
python --version# Upgrade pip and essential tools
python -m ensurepip --upgrade
python -m pip install --upgrade pip setuptools wheel
# Install pythonnet 3.0.5
python -m pip install pythonnet==3.0.5
# Install project requirements
pip install -r requirements.txt# Test pythonnet and .NET integration
import sys, clr
print("Python:", sys.version)
print("pythonnet imported OK:", clr.__version__)
clr.AddReference("System")
import System
print("CLR OK, .NET version:", System.Environment.Version)# Navigate to wrapper directory
cd wrapper
# Build and publish the wrapper
dotnet publish -c Release -r win-x64 --self-contained false -o ./../dlls
# Return to root directory
cd ..# Activate virtual environment (if not already active)
.venv\Scripts\activate
# Run wrapper-based approach
python add_annotation_wrapper.py
# Run manual type resolution approach
python add_annotation_manual.pyGroupDocs.Annotation-for-PythonNet/
βββ π lics/ # put here the license GroupDocs.Annotation.lic file
βββ π dlls/ # Compiled .NET assemblies and dependencies
β βββ GroupDocs.Annotation.dll # Main GroupDocs.Annotation library
β βββ GroupDocs.Annotation.Wrapper.dll # Custom wrapper library
β βββ [other dependencies] # Additional .NET dependencies
βββ π files/ # Sample documents for testing
β βββ resume.docx # Input document for annotation
β βββ annotated.docx # Output document with annotations
βββ π wrapper/ # C# wrapper library source code
β βββ SimpleWrapper.cs # Main wrapper implementation
β βββ GroupDocs.Annotation.Wrapper.csproj # Project file
β βββ bin/ # Build output directory
βββ π add_annotation_wrapper.py # Example: Wrapper-based approach
βββ π add_annotation_manual.py # Example: Manual type resolution
βββ π requirements.txt # Python dependencies
βββ π README.md # This documentation
| Folder/File | Purpose | Contents |
|---|---|---|
lics/ |
Licenses folder | This repository does not contain any license. |
dlls/ |
Compiled assemblies | Contains all .NET DLLs required for runtime, including GroupDocs.Annotation and the custom wrapper |
files/ |
Sample documents | Test documents for annotation examples (input and output) |
wrapper/ |
C# source code | Custom wrapper library that simplifies GroupDocs.Annotation usage |
add_annotation_wrapper.py |
Wrapper example | Demonstrates simplified annotation using the wrapper library |
add_annotation_manual.py |
Manual example | Shows direct type resolution and advanced annotation control |
requirements.txt |
Dependencies | Python package requirements (pythonnet) |
Wrapper Library (wrapper/SimpleWrapper.cs)
- Provides simplified static methods for common annotation tasks
- Handles dependency resolution internally
- Exposes high-level APIs for Python consumption
Python Examples
- Wrapper approach: Simple, high-level API for basic annotation needs
- Manual approach: Full control over annotation creation and customization
Document Review & Collaboration
- Legal firms: Annotate contracts, agreements, and legal documents for review
- Healthcare: Add medical notes and annotations to patient records
- Education: Create interactive learning materials with annotations and feedback
- Real Estate: Mark property details and comments on floor plans and documents
Quality Assurance & Compliance
- Manufacturing: Annotate technical drawings and specifications for quality control
- Financial Services: Add compliance notes and audit trails to financial documents
- Government: Mark up policy documents and regulatory compliance materials
- Insurance: Annotate claim documents and policy reviews
Content Management & Publishing
- Publishing houses: Collaborative editing and review of manuscripts
- Marketing agencies: Annotate design mockups and campaign materials
- Technical writing: Add comments and suggestions to technical documentation
- Translation services: Mark up documents for translation review
Automated Document Processing
- Batch annotation: Process hundreds of documents with consistent annotations
- API integration: Add annotations as part of document processing workflows
- Cloud services: Integrate annotation capabilities into cloud-based applications
- Microservices: Deploy annotation services as part of larger document processing systems
Custom Annotation Workflows
- Form processing: Add validation annotations to form submissions
- Report generation: Automatically annotate reports with analysis results
- Document comparison: Highlight differences between document versions
- Template processing: Apply standard annotations to document templates
The Core Problem: Python developers need to add document annotations but face challenges with:
- Loading .NET libraries with embedded dependencies
- Complex type resolution in pythonnet environments
- Maintaining compatibility across different Python/.NET versions
Our Solution Provides:
- β Simplified Integration: Easy-to-use wrapper for common annotation tasks
- β Full Control: Direct access to all GroupDocs.Annotation features
- β Dependency Resolution: Automatic handling of embedded .NET dependencies
- β Cross-Platform: Works on Windows, Linux, and macOS
- β Production Ready: Tested approaches for real-world applications
This solution represents an early implementation for using GroupDocs.Annotation with pythonnet. While it successfully demonstrates both wrapper-based and manual type resolution approaches, please note:
Current Status:
- β Functional: Both implementation approaches work as demonstrated
- β Tested: Examples have been validated with basic annotation scenarios
β οΈ Limited Testing: Not yet extensively tested across all GroupDocs.Annotation featuresβ οΈ Production Readiness: Requires additional testing for production environments
Before Production Use:
- Comprehensive Testing: Test with your specific document types and annotation requirements
- Performance Validation: Evaluate performance with large documents and batch processing
- Error Handling: Implement robust error handling for edge cases
- Security Review: Ensure compliance with your security and data protection requirements
For Development:
- Use the wrapper approach for quick prototyping and simple annotation tasks
- Use the manual approach when you need full control over annotation properties
- Consider extending the wrapper with additional methods for your specific use cases
We welcome your feedback, test results, and suggestions for improvements! Your input will help us:
- Refine the implementation approaches
- Add more comprehensive examples
- Improve error handling and edge cases
- Explore additional GroupDocs.Annotation features
How to Contribute:
- Test the examples with your documents and use cases
- Report any issues or unexpected behavior
- Suggest additional wrapper methods or examples
- Share your successful integration stories
Core Technologies:
pythonnet, GroupDocs.Annotation, .NET, Python, document annotation, CLR integration, assembly loading, dependency resolution
Document Processing:
document annotation, PDF annotation, Word annotation, Excel annotation, PowerPoint annotation, image annotation, document review, collaborative editing, document markup
Technical Implementation:
wrapper library, type resolution, reflection, embedded dependencies, obfuscated assemblies, pythonnet integration, .NET interop, cross-platform
Business Applications:
document collaboration, quality assurance, compliance, legal document review, healthcare documentation, educational materials, content management, publishing workflow
Development & Integration:
API integration, microservices, cloud services, batch processing, automated workflows, document automation, enterprise solution, production deployment