Handling password required exception
Signature class supports handling required password exception when opening protected documents over class PasswordRequiredException.
Here are the steps to handle incorrect password exception when working with protected documents with GroupDocs.Signature:
- Create new instance of Signature class and pass source document path or stream as a constructor parameter.
- Cover the code that works with Signature object methods (Sign, Verify, Search, Update, Delete) with try - catch block including catching PasswordRequiredException exception.
Following example demonstrates how to handle required password exception.
// skip initialization of LoadOptions with Password
// LoadOptions loadOptions = new LoadOptions(){ Password = "1234567890" }
using (Signature signature = new Signature("protectedPwd.pdf"))
{
try
{
QrCodeSignOptions options = new QrCodeSignOptions("JohnSmith")
{
EncodeType = QrCodeTypes.QR,
Left = 100,
Top = 100
};
// try to sign document to file, we expect for PasswordRequiredException
signature.Sign(outputFilePath, options);
Console.WriteLine("\nSource document signed successfully.\nFile saved at " + outputFilePath);
}
catch(PasswordRequiredException ex)
{
Console.WriteLine($"PasswordRequiredException: {ex.Message}");
}
catch(GroupDocsSignatureException ex)
{
Console.WriteLine($"Common GroupDocsSignatureException: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Common Exception happens only at user code level: {ex.Message}");
}
finally
{
}
}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Signature for .NET examples, plugins, and showcase
- GroupDocs.Signature for Java examples, plugins, and showcase
- Document Signature for .NET MVC UI Example
- Document Signature for .NET App WebForms UI Example
- Document Signature for Java App Dropwizard UI Example
- Document Signature for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.