Take the following steps to start a project and to add some code that processes a filled form:
[C#]
using Leadtools.Forms.Processing;
[Visual Basic]
Imports Leadtools.Forms.Processing
[C#]
//Create the processing engine FormProcessingEngine processingEngine = new FormProcessingEngine();[Visual Basic]
'Create the processing engine Dim processingEngine As FormProcessingEngine = New FormProcessingEngine()
[C#]
processingEngine.Pages.Clear(); //Create a new page for the form. In this case, we know the DPI //of the W9 form we ship is 150. FormPage formPage = new FormPage(1, 150, 150); TextFormField textField = new TextFormField(); textField.Name ="Business Name"; textField.Bounds = new LogicalRectangle(196,327, 1402, 40, LogicalUnit.Pixel); formPage.Add(textField); textField = new TextFormField(); textField.Name = "Address"; textField.Bounds = new LogicalRectangle(196, 496, 892, 35,LogicalUnit.Pixel); formPage.Add(textField); //Add the page with the above defined fields to the engine processingEngine.Pages.Add(formPage);
[Visual Basic]
processingEngine.Pages.Clear() 'Create a new page for the form. In this case, we know the DPI 'of the W9 form we ship is 150. Dim formPage As FormPage = New FormPage(1, 150, 150) DimtextField As TextFormField = New TextFormField() textField.Name ="Business Name" textField.Bounds = New LogicalRectangle(196, 327,1402, 40, LogicalUnit.Pixel) formPage.Add(textField) textField =New TextFormField() textField.Name = "Address" textField.Bounds =New LogicalRectangle(196, 496, 892, 35, LogicalUnit.Pixel) formPage.Add(textField) 'Add the page with the above defined fields to the engine processingEngine.Pages.Add(formPage)
[C#]
private void ProcessForm(RasterImage image,List<PageAlignment> alignment) { processingEngine.OcrEngine= formsOCREngine; string resultsMessage = String.Empty; try { processingEngine.Process(image, alignment); foreach(FormPage formPage in processingEngine.Pages) { foreach(FormField field in formPage) { if (field != null) { resultsMessage = String.Format("{0}{1} = {2}{3}", resultsMessage, field.Name, (field.Result as TextFormFieldResult).Text, Environment.NewLine); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } if (String.IsNullOrEmpty(resultsMessage)) MessageBox.Show("No fields were processed", "FieldProcessing Results"); else MessageBox.Show(resultsMessage, "Field ProcessingResults"); }
[Visual Basic]
Private Sub ProcessForm(ByVal image As RasterImage, ByValalignment As List(Of PageAlignment)) processingEngine.OcrEngine = formsOCREngine Dim resultsMessage As String = String.Empty Try processingEngine.Process(image, alignment) For Each formPage As FormPage In processingEngine.Pages For Each field As FormField In formPage If Not field Is Nothing Then resultsMessage = String.Format("{0}{1} = {2}{3}", resultsMessage, field.Name, (CType(IIf(TypeOf field.Result Is TextFormFieldResult, field.Result, Nothing), TextFormFieldResult)).Text, Environment.NewLine) End If Next field Next formPage Catch ex As Exception MessageBox.Show(ex.Message) End Try If String.IsNullOrEmpty(resultsMessage) Then MessageBox.Show("No fields were processed", "FieldProcessing Results") Else MessageBox.Show(resultsMessage, "Field ProcessingResults") End If End Sub
[C#]
if(recognitionResult.Confidence >= 80) { List<PageAlignment> alignment = new List<PageAlignment>(); for (int k = 0; k < recognitionResult.PageResults.Count;k++) { alignment.Add(recognitionResult.PageResults[k].Alignment); } resultMessage = String.Format("This form has been recognized as a {0}",Path.GetFileNameWithoutExtension(masterFileName)); ProcessForm(image, alignment); break; }[Visual Basic]
If recognitionResult.Confidence >= 80 Then Dim alignment As List(Of PageAlignment) = New List(OfPageAlignment)() Dim k As Integer = 0 Do While k < recognitionResult.PageResults.Count alignment.Add(recognitionResult.PageResults(k).Alignment) k += 1 Loop resultMessage = String.Format("This form has been recognized as a {0}",Path.GetFileNameWithoutExtension(masterFileName)) ProcessForm(image, alignment) break End If
NOTE: If you encounter an "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.