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.
Supported Field Types
- Text fields
These fields allow users to input text information.
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).
- Check boxes
These fields allow users to switch between two states.
- Radio buttons
A set of related buttons. Each button allows users to enable/disable a corresponding option.
- List boxes
A list box field that allows users to select a single or multiple options.
- Combo boxes
A field that allows users to select a single option in the invoked list.
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
andimport-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.
<dx: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 totrue
in the event handler to suppress edit mode activation. - FormFieldValueChanging
- Occurs before changes are applied to a field. Set the
e.Cancel
property totrue
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. To invoke the system Save File dialog to allow users to save the current document to the file system, call the PdfViewer.ShowSaveFileDialogAsync method or the PdfViewerCommands.ShowSaveFileDialog command. Users can also save documents in the Share UI. To invoke it, call the PdfViewer.ShareDocumentAsync method or the PdfViewerCommands.ShareDocument command. 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 the next field in the form:
- FocusPreviousFormField() | PdfViewerCommands.FocusPreviousFormField
- FocusNextFormField() | PdfViewerCommands.FocusNextFormField
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.
<dx:PdfViewer x:Name="pdfViewer" .../>
<dx:DXButton Content="<" ...
Command="{Binding Commands.FocusPreviousFormField, Source={x:Reference pdfViewer}}"/>
<dx:DXButton Content=">" ...
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.