Skip to content

Commit 08bf237

Browse files
SmartFormRecognizer
1 parent 5c598e6 commit 08bf237

2 files changed

Lines changed: 17 additions & 26 deletions

File tree

Document-Processing/SmartDataExtractor/NET/SmartFormRecognizer/recognize-forms .md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,42 +150,30 @@ public async void Button_Click(object sender, RoutedEventArgs e)
150150

151151
## Async variants with CancellationToken
152152

153-
The async overloads accept an optional `CancellationToken` to cancel long-running operations:
153+
The async overloads accept an optional `CancellationToken` to cancel long-running operations.Initially cancellationToken value in default.Based on our requirement we can optimize the cancellationToken value.
154154

155155
- `Task<PdfLoadedDocument> RecognizeFormAsPdfDocumentAsync(Stream inputStream, CancellationToken cancellationToken = default)`
156156
- `Task<Stream> RecognizeFormAsPdfStreamAsync(Stream inputStream, CancellationToken cancellationToken = default)`
157157
- `Task<string> RecognizeFormAsJsonAsync(Stream inputStream, CancellationToken cancellationToken = default)`
158158

159159
Example with cancellation token (PDF stream):
160160

161-
```csharp
162-
public async Task RecognizeWithCancellationAsync(CancellationToken token)
161+
{% tabs %}
162+
{% highlight c# tabtitle="C#" %}
163+
164+
public async Task RecognizeWithCancellationAsync()
163165
{
164166
FormRecognizer recognizer = new FormRecognizer();
165167

166168
using FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
167-
169+
CancellationTokenSource cts = new CancellationTokenSource();
170+
cts.CancelAfter(TimeSpan.FromSeconds(5)); // cancel in 5 seconds
171+
CancellationToken token = cts.Token;
168172
using Stream resultStream = await recognizer.RecognizeFormAsPdfStreamAsync(inputStream, token);
169173

170174
using FileStream fileStream = File.Create("Output.pdf");
171175
await resultStream.CopyToAsync(fileStream, token);
172176
}
173-
```
174-
175-
Notes:
176-
- Always forward cancellation tokens to I/O methods when available.
177-
178-
---
179-
180-
## Common corrections and best practices shown in the examples
181-
182-
- Use `using` (or `await using` for IAsyncDisposable) to ensure streams are disposed.
183-
- Use `FileAccess.Read` when only reading input files.
184-
- Do not reuse mismatched variable names (e.g., `smartFormRecognizer` vs `recognizer`) — pick one consistent name.
185-
- Prefer `async`/`await` in UI event handlers but avoid `async void` except for top-level event handlers; prefer `async Task` where possible for testability.
186177

187-
---
188-
189-
If you want, I can also:
190-
- Add a short snippet showing how to handle `FormRecognizeOptions` with these calls.
191-
- Add a unit test or a small console app sample demonstrating each method.
178+
{% endhighlight %}
179+
{% endtabs %}

Document-Processing/SmartDataExtractor/NET/SmartFormRecognizer/working-with-recognize-option.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ recognizer.FormRecognizeOptions.DetectCheckboxes = true;
5050
{% endtabs %}
5151

5252
### DetectRadioButtons
53-
`DetectRadioButtons` is a boolean property in FormRecognizeOptions that specifies whether the form recognizer should detect radio button elements in the document. When enabled (default: true), the recognizer identifies circular selection controls. Turning this option off can streamline processing, reduce unnecessary output, and improve performance when radio buttons are not relevant to the form you are analyzing.
53+
`DetectRadioButtons` is a boolean property in FormRecognizeOptions that specifies whether the form recognizer should detect radio button elements in the document. When enabled (default: true), the recognizer identifies circular objects in images or in the Pdf documnets then add radio buttons in that identified locations.
5454

5555
{% tabs %}
5656
{% highlight c# tabtitle="C#" %}
@@ -68,7 +68,7 @@ recognizer.FormRecognizeOptions.DetectRadioButtons = true;
6868
{% endtabs %}
6969

7070
### DetectSignatures
71-
`DetectSignatures` is a boolean property in FormRecognizeOptions that controls whether the form recognizer should identify signature fields within a document. When enabled (default: true), the recognizer scans for handwritten-style areas, signature lines, or regions typically used for signing, and includes these detected signature blocks in the structured output.
71+
`DetectSignatures` is a boolean property in FormRecognizeOptions that controls whether the form recognizer should identify signature fields within a document. When enabled (default: true), the recognizer scans for handwritten-style areas, signature lines, or regions typically used for signing, and includes these detected signature blocks in the output.
7272

7373
{% tabs %}
7474
{% highlight c# tabtitle="C#" %}
@@ -101,14 +101,17 @@ recognizer.FormRecognizeOptions.ConfidenceThreshold = 0.9;
101101
{% endtabs %}
102102

103103
### PageRange
104-
`PageRange` is an optional int[,]? property in FormRecognizeOptions that allows you to control exactly which pages of a document the form recognizer should process. Each row in this 2‑dimensional array represents a 1‑based inclusive range in the form [start, end], the recognizer processes all pages in the document. Defining page ranges helps improve performance, reduce unnecessary processing, and target only the sections of the document relevant to your extraction workflow.
104+
`PageRange` is an optional int[,]? property in FormRecognizeOptions that allows you to control exactly which pages of a document the form recognizer should process. Each row in this 2‑dimensional array represents a 1‑based inclusive range in the form [start, end], the recognizer processes all pages in the document. Defining page ranges helps improve performance, reduce unnecessary processing, and target only the sections of the document relevant to your extraction workflow.We can also provide values in single page.Also If we provide values in decending order it will consider as ascending order and perform detection.
105105

106106
{% tabs %}
107107
{% highlight c# tabtitle="C#" %}
108108

109109
FormRecognizer recognizer = new FormRecognizer();
110110

111-
// Set a page range
111+
// Set a page range single
112+
recognizer.FormRecognizeOptions.PageRange = new int[,] { { 3 } };
113+
114+
// Set a page range 2D
112115
recognizer.FormRecognizeOptions.PageRange = new int[,] { { 3, 3 } };
113116

114117
{% endhighlight %}

0 commit comments

Comments
 (0)