Class SfSmartPdfViewer
The SmartPdfViewer is an AI-powered control that extends the Syncfusion.Blazor.SfPdfViewer. It allows for seamless interaction with PDF documents by incorporating AI-assisted functionalities.
Inheritance
Inherited Members
Namespace: Syncfusion.Blazor.SmartPdfViewer
Assembly: Syncfusion.Blazor.SmartPdfViewer.dll
Syntax
public class SfSmartPdfViewer : SfPdfViewer2, IComponent, IHandleEvent, IHandleAfterRender, IDisposable
Examples
<SfSmartPdfViewer Height="100%" width="100%">
</SfSmartPdfViewer>
<SfSmartPdfViewer Height="100%" width="100%">
</SfSmartPdfViewer>
Constructors
SfSmartPdfViewer()
Declaration
public SfSmartPdfViewer()
Methods
ApplySmartFillAsync()
Initiates the Smart Fill process using extracted form field names and the current clipboard data. When executed, this method uses AI to analyze the clipboard content and map it to named form fields within the loaded PDF.
Declaration
public Task ApplySmartFillAsync()
Returns
| Type |
|---|
| Task |
Remarks
The ApplySmartFillAsync() method requires that form fields have valid names; AI cannot populate fields without identifiers.
The clipboard data is parsed and mapped via AI to corresponding fields, minimizing manual entry and improving accuracy.
Examples
The following example shows how to apply Smart Fill for open forms with clipboard content:
<SfSmartPdfViewer @ref="smartPdfViewer">
<SmartFillSettings />
</SfSmartPdfViewer>
@code {
public async void SmartFormFill()
{
await smartPdfViewer.ApplySmartFillAsync();
}
}
ApplySmartFillAsync(string)
Initiates the Smart Fill process using the specified string data instead of clipboard content.
Declaration
public Task ApplySmartFillAsync(string data)
Parameters
| Type | Name | Description |
|---|---|---|
| string | data | The custom data (string value) to be used by the AI for mapping values to form fields during the Smart Fill process. |
Returns
| Type |
|---|
| Task |
Remarks
This overload of ApplySmartFillAsync(string data) gives developers or users full control over the data source for form filling, supporting custom, user-provided, or application-integrated content.
Form fields without proper names cannot be automatically populated, as the AI workflow requires unique keys for mapping values correctly.
Examples
The following example demonstrates how to invoke Smart Fill with your own data:
<SfSmartPdfViewer @ref="smartPdfViewer" >
<SmartFillSettings />
</SfSmartPdfViewer>
@code {
public async void SmartFormFill()
{
await smartPdfViewer.ApplySmartFillAsync("FirstName: Alice; LastName: Smith; Email: [email protected];");
}
}
DetectAndAddFormFieldsAsync(IFormRecognizer, SmartFormRecognizerOptions)
Detects form fields from the currently loaded PDF document and automatically adds the detected fields to the PDF Viewer.
Declaration
public Task DetectAndAddFormFieldsAsync(IFormRecognizer FormRecognizer, SmartFormRecognizerOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormRecognizer | FormRecognizer | The form recognizer instance used to detect form fields from the PDF document. |
| SmartFormRecognizerOptions | options | Specifies the settings used during form field detection. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous operation. The task result contains the collection of detected form fields. |
Remarks
This method analyzes the loaded PDF document using the specified form recognizer Syncfusion.PdfViewer.FormRecognizer.IFormRecognizer instance and adds the detected form fields, such as text boxes, check boxes, radio buttons, and signature fields, to the PDF Viewer. Detection behavior can be customized using SmartFormRecognizerOptions.
Examples
FormRecognizer smartFormRecognizer = new FormRecognizer();
SmartFormRecognizerOptions options = new SmartFormRecognizerOptions
{
ConfidenceThreshold = 0.5,
DetectCheckboxes = true,
DetectRadioButtons = true,
DetectSignatures = true,
DetectTextboxes = true
};
await smartPdfViewer.DetectAndAddFormFieldsAsync(
smartFormRecognizer,
options);
Dispose()
Dispose the Smart PDF Viewer and it's dependencies.
Declaration
public override void Dispose()
Overrides
ExtractFormFieldsAsync(IFormRecognizer, SmartFormRecognizerOptions)
Extracts form field data from the currently loaded PDF document and returns the extracted data as a JSON string.
Declaration
public Task<string> ExtractFormFieldsAsync(IFormRecognizer FormRecognizer, SmartFormRecognizerOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormRecognizer | FormRecognizer | The form recognizer instance used to extract form field data from the PDF document. |
| SmartFormRecognizerOptions | options | Specifies the settings used during form field detection and extraction. |
Returns
| Type | Description |
|---|---|
| Task<string> | A task that represents the asynchronous operation. The task result contains a JSON-formatted string representing the extracted form field data. |
Remarks
This method uses the specified Syncfusion.PdfViewer.FormRecognizer.IFormRecognizer instance to analyze the loaded PDF document and extract detected form field information. The extracted form field data is returned as a JSON-formatted string, which can be used for further processing, storage, or integration with external systems. Detection behavior can be customized using SmartFormRecognizerOptions.
Examples
FormRecognizer smartFormRecognizer = new FormRecognizer();
SmartFormRecognizerOptions options = new SmartFormRecognizerOptions
{
ConfidenceThreshold = 0.5,
DetectCheckboxes = true,
DetectRadioButtons = true,
DetectSignatures = true,
DetectTextboxes = true
};
string formFieldsJson = await smartPdfViewer.ExtractFormFieldsAsync(
smartFormRecognizer,
options);
GetPrompts()
Gets or sets a value indicating whether the response toolbar icons are shown.
Declaration
public List<AssistViewPrompt> GetPrompts()
Returns
| Type | Description |
|---|---|
| List<AssistViewPrompt> |
|
Examples
<SfSmartPdfViewer @ref="settings">
</SfSmartPdfViewer>
@code {
private List<AssistViewPrompt> prompts = new List<AssistViewPrompt>();
protected override void OnAfterRender(bool firstRender)
{
prompts = settings.GetPrompts();
}
}
OnAfterRenderAsync(bool)
Handles the after render event of the component to perform actions after the component has rendered.
Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | firstRender | Indicates the first render |
Returns
| Type |
|---|
| Task |
Overrides
OnInitialized()
Occurs when the control is being initialized
Declaration
protected override void OnInitialized()
Overrides
OnParametersSetAsync()
Updates the component when parameters are set. It is used to detect changes in the component parameters and handle any necessary updates or actions.
Declaration
protected override Task OnParametersSetAsync()
Returns
| Type |
|---|
| Task |