Skip to main content

Fill in Interactive Forms in DevExpress PDF Viewer for .NET MAUI

  • 3 minutes to read

A PDF document can contain interactive forms (AcroForms) where users can fill in data or invoke actions.

DevExpress PDF Viewer for .NET MAUI - Interactive fields

Supported Field Types

Text fields

These fields allow users to input text information.

DevExpress PDF Viewer for .NET MAUI - Interactive fields - Text boxes

The following text field attributes are supported:

  • MaxLen – Specifies the maximum number of input characters.
  • ReadOnly – If set, a user cannot edit this field.
  • Multiline – If set, this field can contain multiple lines. Otherwise, only a single line is allowed.
  • Password – Allows users to enter a password (obscures input text).
Push-buttons

These fields allow users to invoke an assigned action (for example, go to a link or reset a form).

DevExpress PDF Viewer for .NET MAUI - Interactive fields - Push button

Check boxes

These fields allow users to switch between two states.

DevExpress PDF Viewer for .NET MAUI - Interactive fields - Check boxes

Radio buttons

A set of related buttons. Each button allows users to enable/disable a corresponding option.

DevExpress PDF Viewer for .NET MAUI - Interactive fields - Radio buttons

List boxes

A list box field that allows users to select a single or multiple options.

DevExpress PDF Viewer for .NET MAUI - Interactive fields - List box

Combo boxes

A field that allows users to select a single option in the invoked list.

DevExpress PDF Viewer for .NET MAUI - Interactive fields - Combo box

Limitations

Due to security reasons, the PDF viewer does not execute JavaScript code embedded in the document. For this reason, the following features are not supported:

  • submit-form and import-data actions
  • Text field formatting
  • Date-time formats

Highlight Form Fields

Set the HighlightFormFields property to true to highlight all interactive fields. Use the FormFieldHighlightColor property to specify the highlight fill color.

DevExpress PDF Viewer for .NET MAUI

<dxp:PdfViewer ...
               HighlightFormFields="True"
               FormFieldHighlightColor="#80C82C4A">

Respond to User Actions

Handle the following PDF viewer events to respond to user actions:

FormFieldEditorShowing
Occurs once a user taps a field and before an in-place editor appears. Set the e.Cancel property to true in the event handler to suppress edit mode activation.
FormFieldValueChanging
Occurs before changes are applied to a field. Set the e.Cancel property to true in the event handler to cancel value changes. In this case, the PDF viewer does not raise the FormFieldValueChanged event.
FormFieldValueChanged
Occurs after changes are applied to a field.
UriOpening
Occurs when a user taps a push-button that opens a link.
ReferencedDocumentOpening
Occurs when a user taps a push-button to open another PDF document.

Save Changes to the Document

The PDF Viewer does not automatically save field data changes to the document. Users can save documents in the Share UI. To invoke it, call the PdfViewer.ShareDocumentAsync() method or the PdfViewerCommands.ShareDocument command. You can also call the PdfViewer.SaveDocumentAsync method to save the current document to a stream.

Import and Export Field Data

The following PDF viewer methods allow you to import field data from a stream and export to a stream in XML and FDF formats:

Implement Navigation UI Between Fields

Call the following methods/commands to focus the previous or next field in the form:

If no field is currently focused, these methods/commands do nothing.

The following code snippet adds two buttons that allow users to navigate between form fields.

<dxp:PdfViewer x:Name="pdfViewer" .../>
<dx:DXButton Content="&lt;" ...
         Command="{Binding Commands.FocusPreviousFormField, Source={x:Reference pdfViewer}}"/>
<dx:DXButton Content="&gt;" ...
         Command="{Binding Commands.FocusNextFormField, Source={x:Reference pdfViewer}}"/>

Prevent Form Field Editing

Set the PDF viewer’s AllowEditFormFields property to false to switch form fields to read-only mode.

To prohibit all edit actions within the PDF document, enable the IsReadOnly property. This also prevents users from adding annotations, text decorations, and signatures.