Detect a signature on a document

This example shows how to find a signature on a document with the help of a Mixed Print recognition profile and how to save the snippet for further processing to a separate file. The information about the print type is saved in the LongTag property of the box, where the following values are applied:

1 = hand

2 = signature

Define the function CreateSignatureFiles in the project script so that it is accessible from every other script sheet.

This image file can be inserted as a new document by using the AddDocument method.

Tip You can improve the given script sample for detecting signatures by checking the LongTag property for both values, 1 (hand) and 2 (signature), and by evaluating the area above for machine printed text that contains values such as Yours sincerely or Best regards.
Public Function CreateSignatureFiles(pXDoc As CASCADELib.CscXDocument, Prefix as string) As Boolean
   Dim Rep As CscXDocRepresentation
   Dim Box As CscXDocBox
   Dim i As Integer
   Dim ImageOrig As CscImage
   Dim ImageBox As CscImage

   If pXDoc.Representations.Count = 0 Then Exit Sub

   Set Rep = pXDoc.Representations(0)
   For i = 0 To Rep.Boxes.Count - 1
      Set Box = Rep.Boxes(i)
      If Box.LongTag = 2 Then
         Set ImageOrig = pXDoc.CDoc.Pages(Box.PageIndex).GetBitonalImage(Project.ColorConversion)
         Set ImageBox = New CscImage
         ImageBox.CreateImage(CscImageColorFormat.CscImgColFormatBinary, Box.Width, Box.Height, ImageOrig.XResolution, ImageOrig.YResolution)
         ImageBox.CopyRect(ImageOrig, Box.Left, Box.Top, 0, 0, Box.Width, Box.Height)
         ImageBox.Save("C:\Temp\" + Prefix + "_" + CStr(i) + "_(" + CStr(Box.Left) + "," + CStr(Box.Top) + ")_[" + CStr(Box.Width) + "," + CStr(Box.Height) + "]_Type" + CStr(Box.LongTag) + ".tif")
      End If
   Next

End Function

' add the function call to all classes in the Document_Extract event 
' where you expect to have a signature that you want to export
Private Sub Document_Extract(ByVal pXDoc As CASCADELib.CscXDocument)
   CreateSignatureFiles pXDoc, "MyClass"
End Sub