Deleting Text signatures - advanced

GroupDocs.Signature provides TextSignature class to manipulate text signatures and delete them from the documents over Delete method.
Please be aware that Delete method modifies the same document that was passed to constructor of Signature class.

Here are the steps to delete Text signature from the document with GroupDocs.Signature:

  • Create new instance of Signature class and pass source document path as a constructor parameter;
  • Instantiate TextSearchOptions object with desired properties;
  • Call Search method to obtain list of TextSignatures;
  • Select from list TextSignature object(s) that should be removed from the document;
  • Call Signature object Delete method and pass one or several signatures to it.
  • Analyze DeleteResult result to check whether signatures were updated or not.

Here are the alternative steps to delete Text signature from the document with GroupDocs.Signature. This approach is based on saved signatures Id after Search or Sign methods.

  • Create new instance of Signature class and pass source document path as a constructor parameter;
  • Instantiate one or several TextSignature objects with signature Id(s) passed to constructor;
  • Call Signature class object Delete method and pass one or several signatures to it;
  • Analyze DeleteResult result to check whether signatures were updated or not.

This example shows how to delete Text signature that was found using Search method.

// initialize Signature instance
using (Signature signature = new Signature("signed.pdf"))
{
    TextSearchOptions options = new TextSearchOptions();
    List<TextSignature> signatures = signature.Search<TextSignature>(options);
    List<BaseSignature> signaturesToDelete = new List<BaseSignature>();
    // collect signatures to delete
    foreach (TextSignature temp in signatures)
    {
        if (temp.Text.Contains("John"))
        {
            signaturesToDelete.Add(temp);
        }
    }
    // delete signatures
    DeleteResult deleteResult = signature.Delete(signaturesToDelete);
    if (deleteResult.Succeeded.Count == signaturesToDelete.Count)
    {
        Console.WriteLine("All signatures were successfully deleted!");
    }
    else
    {
        Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");
        Console.WriteLine($"Not deleted signatures : {deleteResult.Failed.Count}");
    }
    Console.WriteLine("List of deleted signatures:");
    foreach (BaseSignature temp in deleteResult.Succeeded)
    {
        Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
    }
}

Delete Text signature from the document by known signature Identifier

This example shows how to delete Text signature in the document by known signature Id (that was obtained by Search or Sign method previously).

// initialize Signature instance
using (Signature signature = new Signature("signed.xlsx"))
{
    // read from some data source signature Id value
    string[] signatureIdList = new string[]
    {
        "1dd21cf3-b904-4da9-9413-1ff1dab51974",
        "9e386726-a773-4971-b2fc-eaadfce65ffd"
    };
    // create list of Text Signature by known SignatureId
    List<BaseSignature> signatures = new List<BaseSignature>();
    signatureIdList.ToList().ForEach(p => signatures.Add(new TextSignature(p)));
    // delete required signatures
    DeleteResult deleteResult = signature.Delete(signatures);
    if (deleteResult.Succeeded.Count == signatures.Count)
    {
        Console.WriteLine("All signatures were successfully deleted!");
    }
    else
    {
        Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");
        Console.WriteLine($"Not deleted signatures : {deleteResult.Failed.Count}");
    }
    Console.WriteLine("List of deleted signatures:");
    foreach (BaseSignature temp in deleteResult.Succeeded)
    {
        Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");
    }
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.