Skip to content

946336: Publish UG documentation for 2025 Volume 1 release for SfPdfViewer #3127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: development
Choose a base branch
from
137 changes: 137 additions & 0 deletions MAUI/PDF-Viewer/Form-Filling.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,143 @@ private void PdfViewer_FormFieldValueChanged(object sender, FormFieldValueChange
{% endhighlight %}
Copy link
Collaborator

@Deepak1799 Deepak1799 Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{% endtabs %}

## Customize the form fields programmatically

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still in one of the places only the color is mentioned
image

It is better to have a common term instead of mentioning every time all the fields
image

Customizing form fields allows you to control their appearance and behavior. You can modify properties like background color, border color, border width, and foreground color to adjust how fields such as text boxes, checkboxes, and radio buttons look in the PDF Viewer. These customizations can be undo and redo, but they cannot be changed when a field is locked. The customized colors and border width are preserved during import, export, printing, and saving, ensuring consistency across document operations.

### Customize the background color of the form fields

The `BackgroundColor` property sets the color of the background within a form field. This allows you to customize the background color, which can be useful for changing the forms with specific branding or visual styles in a PDF document. The following code explains how to enable the background color for text form fields. Similarly, you can do the same for other form fields like checkboxes, radio buttons, and other form fields by modifying their respective properties. The following example illustrates how to add a background color for a text form field by accessing the text form field’s `BackgroundColor` property.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the AI for simplify all the other contents also?



{% tabs %}
{% highlight C# %}
foreach (FormField formField in PdfViewer.FormFields)
{
// Check if the current form field is a text form field
if (formField is TextFormField textBoxField)
{
// Loop through all the widgets associated with the text box field
foreach (var widget in textBoxField.Widgets)
{
// Set the background color of each widget to yellow
widget.BackgroundColor = Colors.Yellow;
}
}
}

{% endhighlight %}
{% endtabs %}

### Customize the text color of the form fields

The `ForegroundColor` property sets the color of the text within a form field. This allows you to customize the text color, Text color can be used to highlight important fields or messages in forms. For example, you can set a field's text color to red to draw attention to a mandatory field or a validation error. The following code explains how to enable the ForegroundColor for text form fields. Similarly, you can do the same for other form fields like checkboxes, radio buttons, and other form fields by modifying their respective properties.The following example illustrates how to add a foreground color for a text form field by accessing the text form field’s `ForegroundColor` property.


{% tabs %}
{% highlight C# %}
foreach (FormField formField in PdfViewer.FormFields)
{
// Check if the current form field is a text form field
if (formField is TextFormField textBoxField)
{
// Loop through all the widgets associated with the text box field
foreach (var widget in textBoxField.Widgets)
{
// Set the foreground color of each widget to Red
widget. ForegroundColor = Colors.Red;
}
}
}
{% endhighlight %}
{% endtabs %}



### Customize the border color of the form fields

The `BorderColor` property sets the color of the border around the form field. For users with color blindness, using high-contrast border colors can improve the visibility of the form fields. Additionally, changing the border color to red for an error state can be more noticeable for those with difficulty distinguishing certain colors. The following code explains how to enable the border color for text form fields. Similarly, you can do the same for other form fields like checkboxes, radio buttons, and other form fields by modifying their respective properties.The following example illustrates how to add a border color for a text form field by accessing the text form field’s `BorderColor` property.


{% tabs %}
{% highlight C# %}
foreach (FormField formField in PdfViewer.FormFields)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still the same contradiction occurs
image

// Check if the current form field is a text form field
if (formField is TextFormField textBoxField)
{
// Loop through all the widgets associated with the text box field
foreach (var widget in textBoxField.Widgets)
{
// Set the border color of each widget to Red
widget. BorderColor = Colors.Red;
}
}
}
{% endhighlight %}
{% endtabs %}

### Customize the border width of the form fields

The `BorderWidth` property sets the thickness of the border around a form field. Adjusting the border width of form fields can enhance accessibility by making it easier for users with visual impairments to identify and focus on fields. Thicker borders can create a more pronounced visual hierarchy, making the form easier to navigate. The following code explains how to enable the border width for text form fields. Similarly, you can do the same for other form fields like checkboxes, radio buttons, and other form fields by modifying their respective properties.The following example illustrates how to add a border width for a text form field by accessing the text form field’s `BorderWidth` property.


{% tabs %}
{% highlight C# %}
foreach (FormField formField in PdfViewer.FormFields)
{
// Check if the current form field is a text form field
if (formField is TextFormField textBoxField)
{
// Loop through all the widgets associated with the text box field
foreach (var widget in textBoxField.Widgets)
{
// Set the border color of each widget to 2.0f
widget. BorderWidth = 2.0f;
}
}
}
{% endhighlight %}
{% endtabs %}

## Property changed event for Form fields Widgets

The `PropertyChanged` event occurs when a property is changed in the PDF document. It is common for properties such as border color, background color, border width, and foreground color to trigger this event as well. The following example explains how to wire and handle the event.

{% tabs %}
{% highlight C# %}

void FormFieldWidgetPropertyChangedEvent()
{
// Loop through each FormField in the PdfViewer
foreach (FormField formField in pdfViewer.FormFields)
{
// Loop through each widget within the form field (e.g., text fields, checkboxes, etc.)
foreach (var widget in formField.Widgets)
{
// Subscribe to the PropertyChanged event for each widget
widget.PropertyChanged += Widget_PropertyChanged;
}
}
}
// This event handler is called whenever a property of a widget changes
private void Widget_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// Ensure that the sender is of type Widget
if (sender is Widget widget)
{
// Check if the property that changed is the BorderWidth property of the widget
if (e.PropertyName == nameof(widget.BorderWidth))
{
// Retrieve the current border width of the widget
double width=widget.BorderWidth;
}
}
}

{% endhighlight %}
{% endtabs %}

## Restrict form field editing

The form fields can be prevented from being modified by setting the [ReadOnly](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.FormField.html#Syncfusion_Maui_PdfViewer_FormField_ReadOnly) property. The following example illustrates how to make all form fields read-only.
Expand Down