maui-404953-pdf-viewer-interactive-forms.md
A PDF document can contain interactive forms (AcroForms) where users can fill in data or invoke actions.
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.
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 actionsSet 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">
Handle the following PDF viewer events to respond to user actions:
FormFieldEditorShowingOccurs 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.FormFieldValueChangingOccurs 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.FormFieldValueChangedOccurs after changes are applied to a field.UriOpeningOccurs when a user taps a push-button that opens a link.ReferencedDocumentOpeningOccurs when a user taps a push-button to open another PDF 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.
The following PDF viewer methods allow you to import field data from a stream and export to a stream in XML and FDF formats:
Call the following methods/commands to focus the previous or the 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.
<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}}"/>
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.