Introduction
Ever dealt with a document that’s supposed to have “Confidential” stamped on every page, only to find out someone forgot to add it? Or maybe you’re building a system that needs to verify invoice numbers follow a specific format before processing payments. That’s where text signature verification comes in handy.
Text signatures aren’t just about fancy digital certificates (though we’ve got those covered elsewhere). We’re talking about verifying the actual text content in your documents - watermarks, footer text, stamps, labels, or any text pattern that proves your document is legitimate and hasn’t been tampered with.
Here’s the thing: manually checking hundreds (or thousands) of documents for specific text isn’t just tedious - it’s error-prone. GroupDocs.Signature for .NET solves this by letting you programmatically verify text signatures across PDFs, Word docs, Excel spreadsheets, and pretty much any document format you’re working with.
In this guide, you’ll learn how to implement rock-solid text verification in your .NET applications. We’ll cover everything from basic verification to advanced pattern matching with regex, plus real-world troubleshooting scenarios that’ll save you hours of debugging.
Your First Text Verification in 5 Minutes
If you’re the “show me the code first” type of developer (aren’t we all?), here’s a working example you can copy-paste right now:
using System;
using GroupDocs.Signature;
using GroupDocs.Signature.Domain;
using GroupDocs.Signature.Options;
// Point to your document
string filePath = "sample_document.docx";
// Initialize and verify
using (Signature signature = new Signature(filePath))
{
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "Confidential",
MatchType = TextMatchType.Contains
};
VerificationResult result = signature.Verify(options);
if(result.IsValid)
{
Console.WriteLine("Document contains the required text!");
}
else
{
Console.WriteLine("Verification failed - text not found.");
}
}
That’s it! You’ve just verified text in a document. Now let’s break down what’s actually happening here and explore the powerful options available to you.
Prerequisites
Before we dive deeper, make sure you’ve got these basics covered:
GroupDocs.Signature for .NET: Grab the latest version from the download page. The installation is straightforward - either NuGet package or direct DLL reference.
Development Environment: Visual Studio 2019+ (or VS Code if that’s your jam), with .NET Framework 4.6.1+ or .NET Core 2.0+.
C# Knowledge: You don’t need to be a C# wizard, but you should be comfortable with basic object-oriented programming concepts.
Test Documents: A few sample documents containing text signatures. If you don’t have any, you can create a simple Word doc with some watermarks or footer text.
Valid License (Optional): The library works with a free trial, but you’ll want a license for production. You can get a temporary license for testing.
Import Required Namespaces
Start by importing the necessary namespaces to access the GroupDocs.Signature functionality:
using System;
using GroupDocs.Signature;
using GroupDocs.Signature.Domain;
using GroupDocs.Signature.Options;
These namespaces give you access to everything you need: the main Signature class, domain objects for results, and configuration options for verification behavior.
When to Use Text Verification (And When Not To)
Before we get into the technical details, let’s talk about when text verification is actually the right tool for the job.
Perfect for text verification:
- Verifying watermarks on company documents (“DRAFT”, “CONFIDENTIAL”, etc.)
- Checking invoice or order numbers follow specific patterns
- Validating footer text for compliance (copyright notices, legal disclaimers)
- Ensuring document labels are correctly applied
- Detecting unauthorized document modifications by checking for specific text
Consider alternatives for:
- Digital signatures: If you need cryptographic proof of authenticity, use digital signature verification instead
- Scanned documents: Text verification works on digital text only. For scanned images, you’ll need OCR processing first
- Heavily formatted text: If formatting (colors, fonts) is as important as content, combine text verification with appearance checks
- QR codes or barcodes: Use the dedicated barcode verification methods - they’re optimized for that
Step-by-Step Implementation Guide
Let’s walk through implementing text verification with proper explanations for each step. This isn’t just copy-paste code - you’ll understand why each piece matters.
Step 1: Specify the Document Path
// Path to the document containing text signatures
string filePath = "sample_multiple_signatures.docx";
Pretty straightforward, right? But here’s a pro tip: in production code, you’ll want to validate this path exists before proceeding. Nothing’s more frustrating than a cryptic error message because someone misspelled a filename.
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"Document not found: {filePath}");
}
Step 2: Initialize the Signature Object
// Create an instance of Signature class by passing document path
using (Signature signature = new Signature(filePath))
{
// Verification code will be implemented here
}
The using
statement here is crucial - it ensures the document resources get properly disposed of after we’re done. The Signature class is your main entry point for all GroupDocs operations, and it’s designed to handle multiple signature types, not just text.
One thing that trips up beginners: this initialization doesn’t load the entire document into memory right away. The library uses smart streaming, so even large documents won’t kill your application’s performance.
Step 3: Configure Text Verification Options
// Define text verification options
TextVerifyOptions options = new TextVerifyOptions()
{
AllPages = true, // Check all pages of the document
SignatureImplementation = TextSignatureImplementation.Native,
Text = "signature", // Text to be verified
MatchType = TextMatchType.Contains // Specify matching criteria
};
This is where things get interesting. Let’s break down each option:
AllPages: Setting this to true
means you’re checking every single page. If you know your text signature only appears on the first page (like a cover page stamp), set this to false
and specify PageNumber = 1
to speed things up.
SignatureImplementation: This tells the library how to interpret the text. Native
means text that’s part of the document structure (typed text, watermarks added during document creation). There’s also Sticker
for text that was overlaid later. Most of the time, you’ll want Native
.
Text: The actual content you’re looking for. Case sensitivity matters here by default! If you need case-insensitive matching, you’ll want to use regex matching (we’ll cover that shortly).
MatchType: This is powerful. You’ve got several options:
Contains
: Text appears anywhere (most flexible)Exact
: Perfect match onlyStartsWith
: Text must be at the beginningEndsWith
: Text must be at the endRegex
: Use regular expressions for complex patterns
Step 4: Execute Verification Process
// Perform verification
VerificationResult result = signature.Verify(options);
This single line does all the heavy lifting. Behind the scenes, the library is:
- Opening the document stream
- Parsing the document structure
- Extracting text content from specified pages
- Comparing against your criteria
- Building a detailed result object
The beauty of this API? It works identically whether you’re checking a 1-page PDF or a 500-page Word document.
Step 5: Process Verification Results
// Check verification result and process accordingly
if (result.IsValid)
{
Console.WriteLine($"Document {filePath} contains valid text signatures!");
// Display information about successful signatures
foreach (TextSignature textSignature in result.Succeeded)
{
Console.WriteLine($"\nFound valid text signature:");
Console.WriteLine($"Text: {textSignature.Text}");
Console.WriteLine($"Location: Page {textSignature.PageNumber}, {textSignature.Left}x{textSignature.Top}");
}
}
else
{
Console.WriteLine($"Document {filePath} failed verification process.");
Console.WriteLine($"Number of failed signatures: {result.Failed.Count}");
}
The VerificationResult
object is packed with useful information. IsValid
gives you a quick yes/no answer, but you’ll often want to dig deeper:
- Succeeded: Collection of all text signatures that matched your criteria
- Failed: Signatures that didn’t match (useful for debugging)
- Each signature includes position data (page number, coordinates), which is super helpful for logging or user feedback
In production code, you might log these results to a database, send notifications for failed verifications, or generate compliance reports.
Complete Working Example
Here’s everything put together in a production-ready example with proper error handling:
using System;
using GroupDocs.Signature;
using GroupDocs.Signature.Domain;
using GroupDocs.Signature.Options;
namespace GroupDocs.Signature.Examples
{
class Program
{
static void Main(string[] args)
{
// Document path
string filePath = "sample_multiple_signatures.docx";
try
{
// Initialize Signature instance
using (Signature signature = new Signature(filePath))
{
// Setup verification options
TextVerifyOptions options = new TextVerifyOptions()
{
AllPages = true,
SignatureImplementation = TextSignatureImplementation.Native,
Text = "signature",
MatchType = TextMatchType.Contains
};
// Verify document signatures
VerificationResult result = signature.Verify(options);
// Process verification results
if(result.IsValid)
{
Console.WriteLine($"\nDocument {filePath} was verified successfully!");
foreach (TextSignature item in result.Succeeded)
{
Console.WriteLine($"\nValid signature is found with text: {item.Text}");
Console.WriteLine($"Location: Page {item.PageNumber}, position {item.Left}x{item.Top}");
}
}
else
{
Console.WriteLine($"\nDocument {filePath} failed verification process.");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
Advanced Verification Scenarios
Now that you’ve got the basics down, let’s explore some powerful advanced features that’ll make your verification system much more robust.
Using Regular Expressions for Pattern Matching
Regular expressions are a game-changer when you need to verify text follows a specific format. Invoice numbers, serial codes, date patterns - regex handles it all:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "Invoice\\s+#\\d{5,6}", // Match patterns like "Invoice #12345" or "Invoice #123456"
MatchType = TextMatchType.Regex
};
Here are some practical regex patterns you might use:
Email addresses:
Text = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
Phone numbers (US format):
Text = "\\(\\d{3}\\)\\s*\\d{3}-\\d{4}"
Date patterns (YYYY-MM-DD):
Text = "\\d{4}-\\d{2}-\\d{2}"
One gotcha: remember to escape backslashes in C# strings (use \\
instead of \
) when writing regex patterns.
Verifying Text in Specific Document Areas
Sometimes you don’t want to search the entire document - you know exactly where the text should be. This is common for footer text, header stamps, or signature blocks:
TextVerifyOptions options = new TextVerifyOptions()
{
AllPages = false,
PageNumber = 1, // Verify only on first page
// Define area to search in (coordinates in points)
PagesSetup = new PagesSetup()
{
FirstPage = true,
LastPage = false,
OddPages = false,
EvenPages = false
},
// Rectangle area in millimeters
Rectangle = new Rectangle(10, 10, 100, 30),
Text = "Confidential"
};
Pro tip: The coordinate system can be tricky. If you’re not sure about the coordinates, use a PDF viewer that shows cursor position, or run verification without area restrictions first to see where matching text is located.
Verifying Multiple Text Patterns Simultaneously
Real-world documents often need multiple text signatures verified at once. Rather than running separate verifications, batch them together:
// Create a list of verification options
List<VerifyOptions> listOptions = new List<VerifyOptions>();
// Add first text verification
listOptions.Add(new TextVerifyOptions()
{
Text = "Confidential",
MatchType = TextMatchType.Exact
});
// Add second text verification
listOptions.Add(new TextVerifyOptions()
{
Text = "Do not copy",
MatchType = TextMatchType.Contains
});
// Verify with multiple options
VerificationResult result = signature.Verify(listOptions);
This approach is significantly faster than running separate verification calls, especially for large documents. The library optimizes the document parsing to handle all verifications in a single pass.
Verifying Text with Specific Appearance
Sometimes the how matters as much as the what. You might need to verify that “APPROVED” appears in green text, or that a watermark uses a specific font:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "APPROVED",
MatchType = TextMatchType.Exact,
// Verify specific appearance properties
ForeColor = System.Drawing.Color.Green,
Font = new SignatureFont()
{
FontFamily = "Arial",
FontSize = 12,
Bold = true
}
};
Note: Appearance verification is format-dependent. Not all document formats support all formatting properties. PDFs typically have the best support for appearance properties.
Performance Optimization Tips
When you’re processing hundreds or thousands of documents, performance matters. Here’s how to keep things running smoothly:
1. Target Specific Pages When Possible
Instead of scanning all pages, specify exactly where you expect to find text:
// Slow: checking all 500 pages
options.AllPages = true;
// Fast: checking only page 1
options.AllPages = false;
options.PageNumber = 1;
2. Use More Specific Match Criteria
The more specific your criteria, the faster the verification:
// Slower: checking if text contains any match
MatchType = TextMatchType.Contains
// Faster: exact match allows early exit
MatchType = TextMatchType.Exact
3. Implement Caching for Repeated Verifications
If you’re verifying the same document multiple times with different criteria, consider caching the extracted text content (you’ll need to implement this at your application level).
4. Use Asynchronous Processing for Bulk Operations
When processing multiple documents, use async/await patterns to parallelize operations:
var verificationTasks = documents.Select(async doc =>
{
using (var signature = new Signature(doc))
{
return await Task.Run(() => signature.Verify(options));
}
});
var results = await Task.WhenAll(verificationTasks);
5. Optimize Resource Usage
For high-volume scenarios, implement a resource pool pattern to reuse Signature instances rather than creating new ones for every document.
Signature Type Comparison: Choosing the Right Verification Method
Different scenarios call for different verification approaches. Here’s when to use text verification versus other signature types:
Verification Type | Best For | Performance | Security Level |
---|---|---|---|
Text Signatures | Watermarks, labels, simple content validation | Fast | Low-Medium |
Digital Signatures | Legal documents, contracts, certificates | Medium | High |
QR Code/Barcode | Tracking numbers, encoded data | Fast | Medium |
Image Signatures | Logos, stamps, visual verification | Slow | Medium |
Metadata Signatures | Hidden document properties | Very Fast | Low |
When to combine methods: For maximum security and validation, use multiple verification types. For example, verify both a digital signature (for authenticity) and text watermark (for classification status).
Real-World Use Cases
Let’s look at some practical scenarios where text verification solves real business problems:
Use Case 1: Automated Invoice Processing
Problem: Processing thousands of invoices monthly, need to verify each has a valid invoice number format.
Solution:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "INV-\\d{8}", // Format: INV-12345678
MatchType = TextMatchType.Regex,
AllPages = false,
PageNumber = 1 // Invoices have number on first page
};
Use Case 2: Document Classification Verification
Problem: Ensuring all classified documents have proper security markings on every page.
Solution:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "CONFIDENTIAL",
MatchType = TextMatchType.Exact,
AllPages = true, // Must appear on every page
ForeColor = System.Drawing.Color.Red // Must be red text
};
Use Case 3: Compliance Footer Validation
Problem: Regulatory requirement that all outgoing contracts must have specific legal disclaimer in footer.
Solution:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "This document constitutes a binding agreement",
MatchType = TextMatchType.Contains,
Rectangle = new Rectangle(0, 750, 600, 50), // Footer area
PageNumber = -1 // Last page
};
Best Practices for Production Systems
After implementing hundreds of document verification systems, here are the patterns that consistently lead to success:
1. Always Implement Comprehensive Error Handling
Don’t just catch exceptions - provide meaningful feedback:
try
{
var result = signature.Verify(options);
}
catch (GroupDocsException gdEx)
{
// GroupDocs-specific errors
Log.Error($"Verification error: {gdEx.Message}");
}
catch (IOException ioEx)
{
// File access issues
Log.Error($"Cannot access document: {ioEx.Message}");
}
catch (Exception ex)
{
// Unexpected errors
Log.Error($"Unexpected error during verification: {ex.Message}");
}
2. Choose Appropriate Match Types Based on Requirements
- Use
Contains
for flexible matching when exact position/format may vary - Use
Exact
when precision is critical (legal documents, compliance) - Use
Regex
for format validation (invoice numbers, serial codes) - Use
StartsWith
/EndsWith
for prefix/suffix validation
3. Validate Your Validation Logic
Before deploying, test your verification against:
- Known valid documents (should pass)
- Known invalid documents (should fail)
- Edge cases (empty documents, corrupted files, wrong formats)
- Performance benchmarks (large documents, bulk processing)
4. Log Verification Results for Audit Trails
In production systems, maintain detailed logs:
if (result.IsValid)
{
Logger.Info($"Document {docId} verified successfully at {DateTime.Now}");
Logger.Debug($"Found {result.Succeeded.Count} matching signatures");
}
else
{
Logger.Warning($"Document {docId} failed verification");
Logger.Debug($"Expected text: {options.Text}, Found: {result.Failed.Count} mismatches");
}
5. Consider Case Sensitivity Carefully
Text matching is case-sensitive by default. For case-insensitive verification, use regex with the appropriate flags or normalize text before comparison.
6. Test Thoroughly Across Document Formats
The same verification code works across formats, but behavior can vary:
- PDFs typically have the most reliable text extraction
- Word documents may have formatting complexities
- Spreadsheets require careful page/sheet specification
- Images require OCR preprocessing (not included in GroupDocs.Signature)
7. Implement Proper Resource Cleanup
Always use using
statements or try-finally blocks to ensure resources are released:
using (var signature = new Signature(filePath))
{
// Verification code
} // Resources automatically cleaned up here
Troubleshooting Common Issues
Even with perfect code, you’ll encounter issues. Here’s how to debug the most common problems:
Issue: Text Not Being Detected
Symptoms: Verification returns IsValid = false
even though you can clearly see the text in the document.
Common causes and solutions:
Text is actually an image: Scanned documents or images of text won’t work. Solution: Use OCR preprocessing or switch to image-based verification.
Case sensitivity mismatch: Looking for “CONFIDENTIAL” but document has “Confidential”. Solution: Use regex with case-insensitive flag or normalize text.
Hidden characters or formatting: Extra spaces, special characters, or formatting codes. Solution: Use
Contains
match type instead ofExact
, or clean the input text.Wrong signature implementation type: Text added as annotation vs. native text. Solution: Try both
Native
andSticker
implementation types.
Debugging steps:
// Enable verbose logging to see what text is actually being extracted
var result = signature.Verify(options);
foreach (var sig in result.Failed)
{
Console.WriteLine($"Expected: {options.Text}");
Console.WriteLine($"Found: {sig.Text}");
Console.WriteLine($"Match: {sig.IsSignature}");
}
Issue: Performance Degradation with Large Documents
Symptoms: Verification takes several seconds or minutes for large PDFs or documents with hundreds of pages.
Solutions:
- Target specific pages: Set
AllPages = false
and specify page ranges - Use area restrictions: Define specific regions where text should appear
- Implement caching: Store verification results for unchanged documents
- Use more specific criteria: Exact matches are faster than Contains matches
- Process asynchronously: Don’t block the UI thread for lengthy operations
Performance monitoring:
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
var result = signature.Verify(options);
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds > 5000)
{
Logger.Warning($"Slow verification: {stopwatch.ElapsedMilliseconds}ms for {filePath}");
}
Issue: Inconsistent Results Across Different Document Formats
Symptoms: Same text verification works for PDFs but not for Word documents (or vice versa).
Common causes:
- Different text rendering in different formats
- Format-specific limitations (some formats don’t support all appearance properties)
- Encoding issues with special characters
Solution: Test each supported format individually and adjust options accordingly. Consider format-specific verification logic:
string extension = Path.GetExtension(filePath).ToLower();
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "Confidential",
MatchType = extension == ".pdf" ? TextMatchType.Exact : TextMatchType.Contains
};
Issue: Verification Fails After Document Modification
Symptoms: Previously valid documents now fail verification after being edited.
Common causes:
- Text was modified during editing
- Formatting changes affected text representation
- Document was saved in different format (re-encoding)
- Signature was removed or relocated
Solution: Implement document versioning and re-verification after any modifications. Consider using immutable document storage for critical files.
Issue: Unicode or Special Character Problems
Symptoms: Documents with non-English text or special symbols aren’t being verified correctly.
Solutions:
- Ensure document encoding is properly detected
- Use Unicode-aware string comparison
- Test with actual special characters, not ASCII equivalents
- Be aware of normalization differences (é vs e + combining accent)
// Normalize Unicode strings before comparison if needed
options.Text = "Café".Normalize(NormalizationForm.FormC);
Issue: Memory Issues When Processing Multiple Documents
Symptoms: Application memory usage keeps growing, eventually causing OutOfMemoryException.
Solution: Ensure proper disposal of Signature objects and implement resource pooling:
// Correct: using statement ensures disposal
using (var signature = new Signature(filePath))
{
var result = signature.Verify(options);
}
// Incorrect: memory leak
var signature = new Signature(filePath);
var result = signature.Verify(options);
// signature never disposed!
Debugging Checklist
When verification isn’t working as expected, go through this systematic checklist:
- Verify the document file exists and is readable
- Check file isn’t corrupted (can it open in normal viewer?)
- Confirm text is actual text, not an image of text
- Test with simpler match criteria (Contains instead of Exact)
- Try different SignatureImplementation types (Native vs. Sticker)
- Check for case sensitivity issues
- Look for hidden characters or formatting in the text
- Test with a known-good document to isolate the issue
- Review exception messages and stack traces carefully
- Enable detailed logging to see internal processing
- Check GroupDocs.Signature version compatibility
- Verify license is valid and properly loaded
Conclusion
Text signature verification might seem simple on the surface, but as you’ve seen, there’s real power in the details. Whether you’re validating watermarks on confidential documents, checking invoice number formats, or ensuring compliance footers appear correctly, GroupDocs.Signature for .NET gives you the tools to do it efficiently and reliably.
The key takeaways from this guide:
Start simple, scale up: Begin with basic Contains matching, then add complexity (regex patterns, appearance checking, area restrictions) only when needed.
Performance matters: For production systems handling high document volumes, optimization strategies like targeted page scanning and async processing make a real difference.
Error handling is crucial: Proper exception handling and detailed logging turn debugging nightmares into quick fixes.
Test across formats: What works for PDFs might need tweaking for Word docs or spreadsheets - always test your verification logic across all formats you’ll encounter.
Combine verification types: Text verification is powerful, but combining it with digital signatures or other verification methods creates more robust document security.
By following the patterns and best practices in this guide, you’re well-equipped to build production-ready document verification systems that scale. Start with the quick-start example, experiment with the advanced scenarios, and don’t hesitate to use the troubleshooting section when issues come up (they always do!).
Now go forth and verify those documents with confidence!
FAQs
Can GroupDocs.Signature verify text in scanned documents or images?
No, GroupDocs.Signature verifies digital text that’s embedded in document files - it doesn’t perform OCR (Optical Character Recognition). If you’re working with scanned documents where text appears as images, you’ll need to use OCR software to extract the text first, then apply verification. Many developers use tools like Tesseract OCR to convert scanned documents to searchable PDFs before verification.
Which document formats are supported for text verification?
GroupDocs.Signature supports a comprehensive range of formats including PDF, Microsoft Office (Word, Excel, PowerPoint), OpenDocument formats, images with embedded text (like annotated images), and more. The full list includes: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, ODT, ODS, ODP, and various image formats (when text is part of the file metadata or annotations, not pixel data). Check the official documentation for the complete list.
Can I verify formatted text with specific fonts, colors, or styles?
Yes! GroupDocs.Signature allows you to verify appearance properties including font family, font size, bold/italic styles, and text color. This is particularly useful when you need to verify that specific text not only exists but also appears in a certain format (like ensuring “APPROVED” stamps are in green text). Here’s an example:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "APPROVED",
ForeColor = System.Drawing.Color.Green,
Font = new SignatureFont()
{
FontFamily = "Arial",
FontSize = 14,
Bold = true
}
};
Keep in mind that appearance verification support varies by document format - PDFs typically have the most comprehensive support, while some formats may have limited formatting information available.
Is it possible to verify text in password-protected documents?
Absolutely. GroupDocs.Signature provides options to specify document passwords when opening protected files. You can pass the password through the LoadOptions when initializing the Signature object:
LoadOptions loadOptions = new LoadOptions()
{
Password = "your_document_password"
};
using (Signature signature = new Signature(filePath, loadOptions))
{
// Proceed with verification as normal
var result = signature.Verify(options);
}
This works for password-protected PDFs, encrypted Office documents, and other secured file formats. Just make sure you have the correct password before attempting verification - failed password attempts will throw exceptions.
Can I verify watermarks and background text?
Yes, GroupDocs.Signature can verify both foreground text and background elements like watermarks. The key is using the correct SignatureImplementation setting:
- Use
TextSignatureImplementation.Native
for watermarks that are part of the document structure (like Word watermarks or PDF background text) - Use
TextSignatureImplementation.Sticker
for text that was overlaid on the document
For watermarks specifically, you might want to search specific areas where watermarks typically appear (center of page, diagonal positioning). Here’s an example:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "CONFIDENTIAL",
SignatureImplementation = TextSignatureImplementation.Native,
AllPages = true // Watermarks usually appear on every page
};
If you’re not sure which implementation type your watermark uses, try running verification with both types and see which returns results.
How do I verify text that contains special characters or Unicode?
Special characters and Unicode text are supported, but you need to be careful about encoding. Make sure your C# strings are properly encoded and match the encoding in your document. Here are some tips:
- Use verbatim strings for patterns with backslashes:
@"C:\Path\To\File"
- Normalize Unicode when dealing with accented characters:
text.Normalize(NormalizationForm.FormC)
- Test with actual characters, not ASCII approximations (use ‘é’ not ’e’ if that’s what’s in the document)
- For regex patterns, escape special regex characters properly
Example with Unicode:
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "Café Münchën", // Unicode characters work directly
MatchType = TextMatchType.Contains
};
What’s the difference between text verification and digital signature verification?
This is a common point of confusion, so let’s clarify:
Text Verification (what this guide covers):
- Verifies the presence and content of actual text in documents
- Checks watermarks, labels, stamps, patterns
- Security level: Low to medium (text can be edited)
- Use cases: Document classification, watermark validation, content checking
- Performance: Generally fast
Digital Signature Verification:
- Verifies cryptographic signatures that prove document authenticity
- Cannot be forged or replicated without the private key
- Security level: High (cryptographically secure)
- Use cases: Legal documents, contracts, certificates
- Performance: Medium (cryptographic operations required)
For maximum security, many organizations use both: digital signatures to prove authenticity and text signatures to indicate document classification or status. They serve complementary purposes.
Can I verify multiple different text patterns in a single document?
Yes, and it’s actually more efficient to batch them together. Rather than running separate Verify() calls, create a list of verification options and pass them all at once:
List<VerifyOptions> verifyOptions = new List<VerifyOptions>
{
new TextVerifyOptions()
{
Text = "Confidential",
MatchType = TextMatchType.Exact
},
new TextVerifyOptions()
{
Text = "Invoice #\\d{5}",
MatchType = TextMatchType.Regex
},
new TextVerifyOptions()
{
Text = "Page \\d+ of \\d+",
MatchType = TextMatchType.Regex
}
};
VerificationResult result = signature.Verify(verifyOptions);
The library optimizes document parsing to handle all verifications in a single pass, which is significantly faster than multiple separate verification calls. The result object will indicate which verifications passed and which failed.
How do I handle case-insensitive text verification?
Text matching in GroupDocs.Signature is case-sensitive by default. For case-insensitive matching, you have two options:
Option 1: Use regex with case-insensitive flag (recommended):
TextVerifyOptions options = new TextVerifyOptions()
{
Text = "(?i)confidential", // (?i) makes it case-insensitive
MatchType = TextMatchType.Regex
};
Option 2: Normalize your search criteria by testing multiple cases:
List<VerifyOptions> caseVariations = new List<VerifyOptions>
{
new TextVerifyOptions() { Text = "Confidential" },
new TextVerifyOptions() { Text = "CONFIDENTIAL" },
new TextVerifyOptions() { Text = "confidential" }
};
The regex approach is cleaner and more efficient, especially when you’re dealing with complex patterns.
What happens if verification takes too long on large documents?
Performance issues with large documents are common, but manageable. Here’s a systematic approach:
- Target specific pages instead of checking all pages:
options.AllPages = false;
options.PageNumber = 1; // Check only first page
- Define specific areas where text should appear:
options.Rectangle = new Rectangle(0, 750, 600, 50); // Footer area only
- Use exact matching instead of Contains when possible (faster):
options.MatchType = TextMatchType.Exact; // Allows early exit
- Process asynchronously for bulk operations:
var verifyTask = Task.Run(() => signature.Verify(options));
- Implement timeouts to prevent indefinite hangs:
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
// Note: GroupDocs doesn't directly support cancellation tokens,
// so wrap in Task.Run with timeout handling
If you’re consistently processing documents over 100 pages, consider implementing a caching strategy where you store verification results and only re-verify when documents change.
Can I extract and verify text from specific sections like headers or footers?
Yes, by using the Rectangle property to define specific areas. Here’s how to target common document sections:
Footer area (bottom of page):
options.Rectangle = new Rectangle(0, 750, 600, 50);
Header area (top of page):
options.Rectangle = new Rectangle(0, 0, 600, 50);
Signature block (bottom right):
options.Rectangle = new Rectangle(400, 700, 200, 100);
The coordinate system uses points (1/72 of an inch) from the top-left corner of the page. Standard US Letter page size is approximately 612x792 points. You may need to experiment with coordinates for your specific documents, or use a PDF viewer that shows cursor coordinates to determine exact positions.
Related Resources
- GroupDocs.Signature .NET API Reference - Complete API documentation with all classes and methods
- Download GroupDocs.Signature for .NET - Latest releases and version history
- Complete Documentation - Comprehensive guides and tutorials
- Product Page - Features, pricing, and product information
- Support Forum - Community support and discussions
- Get a Temporary License - Free trial license for testing