# pdf-viewer-form-filling

> PDF viewer supports form field editing, saving, XFDF import/export, and annotations.

**Framework:** maui  **Component:** PdfViewer  **Variant:** form-filling

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/maui/pdf-viewer-form-filling.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Maui.PdfViewer
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/pdf-viewer-form-filling/PdfViewer.xaml

```xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:pdf="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"
             xmlns:model="clr-namespace:MAUI.Controls.PdfViewer.FormFilling"
             x:Class="MAUI.Controls.PdfViewer.FormFilling.PdfViewerView"
             x:DataType="model:PdfViewerViewModel"
             Title="PDF Viewer - Form Filling">
      <ContentPage.Resources>
        <Style TargetType="Button">
            <Setter Property="BorderWidth" Value="0" />
            <Setter Property="FontSize" Value="18" />
            <Setter Property="Padding" Value="4" />
            <Setter Property="VerticalOptions" Value="Center" />
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal">
                            <VisualState.Setters>
                                <Setter Property="TextColor" Value="#99000000" />
                                <Setter Property="BackgroundColor" Value="Transparent" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="Disabled">
                            <VisualState.Setters>
                                <Setter Property="TextColor" Value="#44000000" />
                                <Setter Property="BackgroundColor" Value="Transparent" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <VisualState.Setters>
                                <Setter Property="TextColor" Value="#99000000" />
                                <Setter Property="BackgroundColor" Value="#0F000000" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ContentPage.Resources>
    <ContentPage.Content>
        <Grid RowDefinitions="40,*">
            <HorizontalStackLayout Grid.Row="0" Spacing="20" Margin="20,0,0,0"
                        HorizontalOptions="Start">
                <Button Text="&#xe712;" 
                        Command="{Binding OpenFileCommand}"
                        IsVisible="{OnPlatform MacCatalyst=false}"
                        FontFamily="MauiMaterialAssets"/>
                <Button Text="&#xe75f;" x:Name="Save" FontFamily="MauiMaterialAssets"  Clicked="Save_Clicked" Margin="0,0,3,0"/>
                <Button x:Name="Import" Text="&#xe782;" FontFamily="MauiMaterialAssets"  Clicked="Import_Clicked"/>
                <Button x:Name="Export" Text="&#xe781;" FontFamily="MauiMaterialAssets"  Clicked="Export_Clicked"/>
                <Button x:Name="ToggleFieldEditing" Text="Toggle field editing"  Clicked="OnToggleEditingClicked"/>
            </HorizontalStackLayout>
            <syncfusion:SfPdfViewer x:Name="pdfViewer" ShowToolbars="False" Grid.Row="1" DocumentSource="{Binding DocumentStream}"/>
        </Grid>
    </ContentPage.Content>
</ContentPage>

```

### src/components/pdf-viewer-form-filling/PdfViewer.xaml.cs

```cs
using Syncfusion.Maui.PdfViewer;

namespace MAUI.Controls.PdfViewer.FormFilling
{
    public partial class PdfViewerView : ContentPage
    {

        public PdfViewerView(PdfViewerViewModel viewModel)
        {
            InitializeComponent();
            BindingContext = viewModel;
        }

        private void OnToggleEditingClicked(object? sender, EventArgs e) =>
            pdfViewer.AllowEditFormFields = !pdfViewer.AllowEditFormFields;

 private async void Save_Clicked(object sender, EventArgs e)
        {
            string targetFile = Path.Combine(FileSystem.Current.AppDataDirectory, "Saved.pdf");
            using FileStream outputStream = File.Create(targetFile);
            pdfViewer.SaveDocument(outputStream);
            await DisplayAlertAsync("Document Saved", "The document has been saved to the file " + targetFile, "OK");
        }
        /// <summary>
        /// Handles the event when the "Import" button is clicked, importing annotations from an XFDF file.
        /// </summary>
        private async void Import_Clicked(object sender, EventArgs e)
        {
            string fileName = Path.Combine(FileSystem.Current.AppDataDirectory, "Export.xfdf");
            if (File.Exists(fileName))
            {
                Stream inputStream = File.OpenRead(fileName);
                inputStream.Position = 0;
                pdfViewer.ImportFormData(inputStream, Syncfusion.Pdf.Parsing.DataFormat.XFdf);
                await DisplayAlertAsync("Form data imported", "Form data from the " + fileName + " file are imported", "OK");
            }
            else
                await DisplayAlertAsync("No files to import", "There are no xfdf files to import. Please export the form data to an xfdf file and then import. ", "OK");
        }

        /// <summary>
        /// Handles the event when the "Export" button is clicked, exporting annotations to an XFDF file.
        /// </summary>
        private async void Export_Clicked(object sender, EventArgs e)
        {
            Stream xfdfStream = new MemoryStream();
            pdfViewer.ExportFormData(xfdfStream, Syncfusion.Pdf.Parsing.DataFormat.XFdf);
            await CopyFileToAppDataDirectory(xfdfStream, "Export.xfdf");
        }
        /// <summary>
        /// Copies the contents of the input stream to a file in the application's data directory.
        /// </summary>
        /// <param name="inputStream">The input stream containing the data to be copied.</param>
        /// <param name="filename">The name of the target file.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task CopyFileToAppDataDirectory(Stream inputStream, string filename)
        {
            // Create an output filename
            string targetFile = Path.Combine(FileSystem.Current.AppDataDirectory, filename);
            // Copy the file to the AppDataDirectory
            using FileStream outputStream = File.Create(targetFile);
            await inputStream.CopyToAsync(outputStream);
            await DisplayAlertAsync("Form data exported", "The form data are exported to the file " + targetFile, "OK");
        }

    }
}

```
