# pdf-viewer-digital-signature

> PDF viewer enables signature validation and signing, with signature panel and save controls.

**Framework:** maui  **Component:** PdfViewer  **Variant:** digital-signature

## 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-digital-signature.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-digital-signature/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.DigitalSignature"
             x:Class="MAUI.Controls.PdfViewer.DigitalSignature.PdfViewerView"
             x:DataType="model:PdfViewerViewModel"
             Title="PDF Viewer - Digital Signature">
    <Style x:Key="buttonIconStyle"
            TargetType="Button">
        <Setter Property="BackgroundColor"
                Value="Transparent"/>

        <Setter Property="VisualStateManager.VisualStateGroups">
            <VisualStateGroupList>
                <VisualStateGroup x:Name="CommonStates">

                    <VisualState x:Name="Normal"/>

                    <VisualState x:Name="PointerOver">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor"
                                    Value="#E7E0EC"/>
                        </VisualState.Setters>
                    </VisualState>

                    <VisualState x:Name="Pressed">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor"
                                    Value="#D0C9D6"/>
                        </VisualState.Setters>
                    </VisualState>

                    <VisualState x:Name="Disabled">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor"
                                    Value="Transparent"/>
                        </VisualState.Setters>
                    </VisualState>

                </VisualStateGroup>
            </VisualStateGroupList>
        </Setter>

        <Style.Triggers>

            <Trigger TargetType="Button"
                     Property="IsEnabled"
                     Value="True">
                <Setter Property="BackgroundColor"
                        Value="Transparent"/>
                <Setter Property="Opacity"
                        Value="1"/>
            </Trigger>

            <Trigger TargetType="Button"
                     Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        Value="0.25"/>
            </Trigger>

            <Trigger TargetType="Button"
                     Property="IsPressed"
                     Value="True">
                <Setter Property="BackgroundColor"
                        Value="#261C1B1E"/>
            </Trigger>

        </Style.Triggers>

    </Style>

    <Style x:Key="DialogContainerStyle"
            TargetType="Border">
        <Setter Property="BackgroundColor"
                Value="#F3EDF7"/>
        <Setter Property="StrokeThickness"
                Value="1"/>
        <Setter Property="Stroke"
                Value="#E5E5E5"/>
        <Setter Property="Padding"
                Value="24"/>
    </Style>

    <Style x:Key="DialogLabelStyle"
            TargetType="Label">
        <Setter Property="FontSize"
                Value="14"/>
        <Setter Property="TextColor"
                Value="#1F1F1F"/>
        <Setter Property="Margin"
                Value="0,12,0,6"/>
    </Style>

    <Style x:Key="DialogButtonStyle"
            TargetType="Button">
        <Setter Property="FontSize"
                Value="14"/>
        <Setter Property="Padding"
                Value="16,12"/>
        <Setter Property="CornerRadius"
                Value="6"/>
        <Setter Property="Margin"
                Value="0,12,0,0"/>
    </Style>

    <Style x:Key="TextInputLayoutStyle"
           TargetType="inputLayout:SfTextInputLayout">
        <Setter Property="ContainerBackground"
                Value="#F8F8F8"/>
        <Setter Property="Margin"
                Value="0,6,0,0"/>
        <Setter Property="HeightRequest"
                Value="40"/>
        <Setter Property="ShowHint"
                Value="True"/>
        <Setter Property="IsHintAlwaysFloated"
                Value="False"/>
        <Setter Property="ReserveSpaceForAssistiveLabels"
                Value="False"/>
        <Setter Property="InputViewPadding">
            <Setter.Value>
                <OnIdiom x:TypeArguments="Thickness">
                    <OnIdiom.Phone>
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="Android">16,10,0,0</On>
                            <On Platform="iOS">16,0,0,0</On>
                        </OnPlatform>
                    </OnIdiom.Phone>
                    <OnIdiom.Tablet>16,10,0,0</OnIdiom.Tablet>
                    <OnIdiom.Desktop>16,0,0,0</OnIdiom.Desktop>
                </OnIdiom>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="PrimaryDialogButtonStyle"
           TargetType="Button"
           BasedOn="{StaticResource DialogButtonStyle}">
        <Setter Property="BackgroundColor"
                Value="#6750A4"/>
        <Setter Property="TextColor"
                Value="#FFFFFF"/>
    </Style>

    <Style x:Key="SecondaryDialogButtonStyle"
           TargetType="Button"
           BasedOn="{StaticResource DialogButtonStyle}">
        <Setter Property="BackgroundColor"
                Value="#EDEBE9"/>
        <Setter Property="TextColor"
                Value="#323130"/>
    </Style>

    </ContentPage.Resources>

    <ContentPage.Content>

        <Grid RowDefinitions="Auto,*">
            <Grid Grid.Row="0"
                  BackgroundColor="#F3EDF7">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!-- Open -->
                <Button Grid.Column="0"
                        x:Name="OpenButton"
                        Style="{StaticResource buttonIconStyle}"
                        Text="&#xE712;"
                        FontFamily="MauiMaterialAssets"
                        FontSize="24"
                        HeightRequest="40"
                        WidthRequest="40"
                        Margin="12,5,0,5"
                        Padding="5"
                        BorderWidth="0"
                        CornerRadius="5"
                        TextColor="#49454F"
                        Clicked="OnOpenClicked"/>

                <BoxView Grid.Column="1"
                         WidthRequest="2"
                         HeightRequest="30"
                         Margin="12,5,0,5"
                         BackgroundColor="#49454F"/>

                <!-- Digital ID -->
                <Button Grid.Column="2"
                        x:Name="DigitalSignatureButton"
                        Style="{StaticResource buttonIconStyle}"
                        Text="Digital ID"
                        FontSize="16"
                        HeightRequest="40"
                        WidthRequest="90"
                        MinimumWidthRequest="90"
                        Margin="12,5,0,5"
                        Padding="5"
                        BorderWidth="0"
                        CornerRadius="5"
                        TextColor="#49454F"
                        Clicked="OnDigitalSignatureClicked"/>

                <!-- Save -->
                <Button Grid.Column="4"
                        x:Name="SaveButton"
                        Style="{StaticResource buttonIconStyle}"
                        Text="&#xe75f;"
                        FontFamily="MauiMaterialAssets"
                        FontSize="24"
                        HeightRequest="40"
                        WidthRequest="40"
                        Margin="0,5,12,5"
                        Padding="5"
                        BorderWidth="0"
                        CornerRadius="5"
                        TextColor="#49454F"
                        Clicked="OnSaveClicked"/>

                <!-- Signature Panel -->
                <Button Grid.Column="5"
                        x:Name="SignaturePanelButton"
                        Style="{StaticResource buttonIconStyle}"
                        Text="&#xE737;"
                        FontFamily="MauiMaterialAssets"
                        FontSize="24"
                        HeightRequest="40"
                        WidthRequest="40"
                        Margin="0,5,12,5"
                        Padding="5"
                        BorderWidth="0"
                        CornerRadius="5"
                        TextColor="#49454F"
                        Clicked="OnSignaturePanelClicked"/>

                <!-- Bottom Separator -->
                <BoxView Grid.ColumnSpan="5"
                         HeightRequest="1"
                         VerticalOptions="End"
                         BackgroundColor="#CAC4D0"/>

            </Grid>

            <!-- PDF Viewer -->
            <Grid Grid.Row="1">

                <syncfusion:SfPdfViewer x:Name="pdfViewer"
                                        ShowToolbars="False"
                                        DocumentSource="{Binding PdfDocumentStream}"/>

            </Grid>

            <!-- Digital ID dialog -->
            <Grid x:Name="SignatureDialogControl"
                  Grid.Row="1"
                  IsVisible="True">
                <Border x:Name="DesktopContainer"
                        Style="{StaticResource DialogContainerStyle}"
                        MaximumWidthRequest="500"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"
                        Padding="20">
                    <Border.StrokeShape>
                        <RoundRectangle CornerRadius="16"/>
                    </Border.StrokeShape>
                    <ScrollView>
                        <VerticalStackLayout Spacing="0">
                            <Grid ColumnDefinitions="*,Auto"
                                    Margin="0,0,0,16">
                                <Label Grid.Column="0"
                                       Text="Sign with Digital ID"
                                       FontSize="18"
                                       FontAttributes="Bold"
                                       TextColor="#000000"
                                       VerticalOptions="Center"/>
                                <Button Grid.Column="1"
                                        Text="&#xE70b;"
                                        FontFamily="MauiMaterialAssets"
                                        FontSize="20"
                                        BackgroundColor="Transparent"
                                        TextColor="#49454F"
                                        BorderWidth="0"
                                        WidthRequest="32"
                                        HeightRequest="32"
                                        Padding="0"
                                        Clicked="OnCloseDialogClicked"/>
                            </Grid>

                            <Border Padding="12"
                                    Margin="0,0,0,16"
                                    BackgroundColor="#EADDFF"
                                    StrokeThickness="0"
                                    HorizontalOptions="Fill">
                                <Border.StrokeShape>
                                    <RoundRectangle CornerRadius="8"/>
                                </Border.StrokeShape>
                                <Grid ColumnDefinitions="Auto,*"
                                      ColumnSpacing="8"
                                      HorizontalOptions="Fill">
                                    <Label Grid.Column="0"
                                           Text="&#9432;"
                                           FontSize="14"
                                           TextColor="#6750A4"
                                           VerticalOptions="Start"
                                           LineBreakMode="NoWrap"/>
                                    <Label Grid.Column="1"
                                           LineBreakMode="WordWrap"
                                           HorizontalOptions="Fill"
                                           HorizontalTextAlignment="Start"
                                           VerticalOptions="Fill"
                                           VerticalTextAlignment="Start">
                                        <Label.FormattedText>
                                            <FormattedString>
                                                <Span Text="Select a Digital ID to sign the document. If no Digital ID is selected, "
                                                      FontSize="12"
                                                      TextColor="#1D192B"/>
                                                <Span Text="the default Digital ID will be used automatically."
                                                      FontSize="12"
                                                      FontAttributes="Bold"
                                                      TextColor="#1D192B"/>
                                            </FormattedString>
                                        </Label.FormattedText>
                                    </Label>
                                </Grid>
                            </Border>

                            <Label Text="Certificate File"
                                   Style="{StaticResource DialogLabelStyle}"
                                   FontAttributes="Bold"/>
                            <Button x:Name="SelectCertificateButton"
                                    Text="Select Certificate (.pfx)"
                                    Style="{StaticResource SecondaryDialogButtonStyle}"
                                    Clicked="OnSelectCertificateClicked"/>
                            <Label x:Name="CertificateFileName"
                                   Text="No certificate selected"
                                   FontSize="12"
                                   TextColor="#666666"
                                   Margin="0,8,0,0"/>

                            <Label Text="Certificate Password *"
                                   Style="{StaticResource DialogLabelStyle}"
                                   FontAttributes="Bold"/>
                            <inputLayout:SfTextInputLayout x:Name="passwordInputLayout"
                                                           Style="{StaticResource TextInputLayoutStyle}"
                                                           Hint="Enter password">
                                <Entry x:Name="PasswordEntry"
                                       BackgroundColor="Transparent"
                                       TextChanged="PasswordEntry_TextChanged"
                                       IsPassword="True"
                                       Placeholder="Enter password"
                                       TextColor="#1F1F1F"
                                       PlaceholderColor="#8A8886"
                                       Focused="PasswordEntry_Focused"
                                       Unfocused="PasswordEntry_Unfocused"
                                       ClearButtonVisibility="Never"
                                       VerticalTextAlignment="Center"/>
                            </inputLayout:SfTextInputLayout>
                            <Label x:Name="PasswordErrorLabel"
                                   FontSize="12"
                                   TextColor="#B3261E"
                                   Margin="0,4,0,0"
                                   IsVisible="False"/>

                            <Label Text="Location (Optional)"
                                   Style="{StaticResource DialogLabelStyle}"/>
                            <inputLayout:SfTextInputLayout x:Name="locationInputLayout"
                                                           Style="{StaticResource TextInputLayoutStyle}"
                                                           Hint="e.g., Vancouver, BC, Canada">
                                <Entry x:Name="LocationEntry"
                                       BackgroundColor="Transparent"
                                       TextColor="#1F1F1F"
                                       Placeholder="e.g., Vancouver, BC, Canada"
                                       PlaceholderColor="#8A8886"
                                       Focused="LocationEntry_Focused"
                                       Unfocused="LocationEntry_Unfocused"
                                       ClearButtonVisibility="Never"
                                       VerticalTextAlignment="Center"/>
                            </inputLayout:SfTextInputLayout>

                            <Label Text="Reason (Optional)"
                                   Style="{StaticResource DialogLabelStyle}"/>
                            <inputLayout:SfTextInputLayout x:Name="reasonInputLayout"
                                                           Style="{StaticResource TextInputLayoutStyle}"
                                                           Hint="e.g., Document approved">
                                <Entry x:Name="ReasonEntry"
                                       BackgroundColor="#F3F3F3"
                                       TextColor="#1F1F1F"
                                       Placeholder="e.g., Document approved"
                                       PlaceholderColor="#8A8886"
                                       Focused="ReasonEntry_Focused"
                                       Unfocused="ReasonEntry_Unfocused"
                                       ClearButtonVisibility="Never"
                                       VerticalTextAlignment="Center"/>
                            </inputLayout:SfTextInputLayout>

                            <Label Text="Contact Information (Optional)"
                                   Style="{StaticResource DialogLabelStyle}"/>
                            <inputLayout:SfTextInputLayout x:Name="contactinfoInputLayout"
                                                           Style="{StaticResource TextInputLayoutStyle}"
                                                           Hint="e.g., john@company.com">
                                <Entry x:Name="ContactInfoEntry"
                                       BackgroundColor="#F3F3F3"
                                       TextColor="#1F1F1F"
                                       PlaceholderColor="#8A8886"
                                       Placeholder="e.g., john@company.com"
                                       Focused="ContactInfoEntry_Focused"
                                       Unfocused="ContactInfoEntry_Unfocused"
                                       ClearButtonVisibility="Never"
                                       VerticalTextAlignment="Center"/>
                            </inputLayout:SfTextInputLayout>

                            <Grid ColumnDefinitions="*,*"
                                    ColumnSpacing="12"
                                    Margin="0,24,0,0">
                                <Button Grid.Column="0"
                                        Text="Cancel"
                                        Style="{StaticResource SecondaryDialogButtonStyle}"
                                        Clicked="OnCancelClicked"/>
                                <Button Grid.Column="1"
                                        Text="Apply Signature"
                                        Style="{StaticResource PrimaryDialogButtonStyle}"
                                        Clicked="OnApplySignatureClicked"/>
                            </Grid>
                        </VerticalStackLayout>
                    </ScrollView>
                </Border>
            </Grid>
        </Grid>

    </ContentPage.Content>
</ContentPage>

```

### src/components/pdf-viewer-digital-signature/PdfViewer.xaml.cs

```cs
namespace MAUI.Controls.PdfViewer.DigitalSignature
{
    public partial class PdfViewerView : ContentPage
    {
        string? currentFileName = "form_document.pdf";
        public Stream? CertificateStream { get; set; }
        public string? CertificatePassword { get; set; }
        public string? Location { get; set; }
        public string? Reason { get; set; }
        public string? ContactInfo { get; set; }
        private const string DefaultCertificatePassword = "password123";

        public PdfViewerView(PdfViewerViewModel viewModel)
        {
            InitializeComponent();
            BindingContext = viewModel;
            pdfViewer.DigitalSignatureSettings.EnableValidation = true;
            pdfViewer.DigitalSignatureSettings.IsValidationBannerVisible = true;
            pdfViewer.DigitalSignatureSettings.EnableSigning = true;
            pdfViewer.DigitalSignatureModalViewAppearing += PdfViewer_DigitalSignatureModalViewAppearing;
            pdfViewer.SigningFailed += PdfViewer_SigningFailed;
        }

        private async void PdfViewer_SigningFailed(object? sender, SigningFailedEventArgs e)
        {
            string message =
                $"Error Type: {e.ErrorType}\n\n" +
                $"Message: {e.ErrorMessage}";

            if (e.InnerException != null)
            {
                message += $"\n\nException: {e.InnerException.Message}";
            }

            await DisplayAlertAsync("Signing Failed", message, "OK");
        }

        private void PdfViewer_DigitalSignatureModalViewAppearing(object? sender, DigitalSignatureModalViewAppearingEventArgs e)
        {
            // Use the user-selected certificate if one was picked; otherwise fall back
            // to the certificate.pfx bundled with the SampleBrowser.
            Stream? certificateStream = CertificateStream;
            string? certificatePassword = CertificatePassword;

            if (certificateStream == null || string.IsNullOrWhiteSpace(certificatePassword))
            {
                certificateStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Component.Resources.Pdf.certificate.pfx");
                certificatePassword = DefaultCertificatePassword;
            }

            e.Options = new SigningOptions
            {
                SignatureField = e.SignatureField,
                CertificateStream = certificateStream,
                CertificatePassword = certificatePassword,
                Reason = Reason,
                LocationInfo = Location,
                ContactInfo = ContactInfo,
                DigestAlgorithm = DigestAlgorithm.SHA256,
                CryptographicStandard = CryptographicStandard.CADES,
                Appearance = new SignatureAppearanceSettings
                {
                    ShowSignerName = true,
                    ShowDate = true,
                    ShowReason = true,
                    ShowLocation = true
                }
            };

        }

        /// <summary>
        /// Handles when leaving the current page
        /// </summary>
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            pdfViewer?.UnloadDocument();
            pdfViewer?.Handler?.DisconnectHandler();
        }

        private async void OnOpenClicked(object? sender, EventArgs? e)
        {
            // Define platform-specific file types for the file picker.
            FilePickerFileType pdfFileType = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>{
                    { DevicePlatform.iOS, new[] { "com.adobe.pdf" } },
                    { DevicePlatform.Android, new[] { "application/pdf" } },
                    { DevicePlatform.WinUI, new[] { "pdf" } },
                    { DevicePlatform.MacCatalyst, new[] { "pdf" } },
                });

            // Configure the file picker options.
            PickOptions options = new()
            {
                PickerTitle = "Choose a PDF file",
                FileTypes = pdfFileType,
            };

            // Launch the file picker and wait for user selection.
            var result = await FilePicker.Default.PickAsync(options);

            // Check if a file was selected.
            if (result != null)
            {
                // Ensure the file has a name.
                if (result.FileName != null)
                {
                    // Validate the file extension (case-insensitive).
                    if (result.FileName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
                    {
                        currentFileName = result.FileName;
                        // Get the stream.
                        Stream pdfStream = await result.OpenReadAsync();

                        // Load the Pdf in the PdfViewer control using LoadDocument method
                        pdfViewer.LoadDocument(pdfStream);
                    }
                }
            }

        }

        private void OnDigitalSignatureClicked(object? sender, EventArgs? e)
        {
            SignatureDialogControl.IsVisible = true;
        }

        private async void OnSaveClicked(object? sender, EventArgs? e)
        {
            // Create a new memory stream to hold the saved PDF document
            Stream saveDocumentStream = new MemoryStream();

            // Asynchronously save the current document content into the memory stream
            await pdfViewer.SaveDocumentAsync(saveDocumentStream);
            saveDocumentStream.Position = 0;

            // Save the pdf in the local storage using SaveAsync method in the `FileSaver` class present in the CommunityToolkit.Maui source.

            if (!string.IsNullOrEmpty(currentFileName))
            {
                var fileSaverResult = await FileSaver.Default.SaveAsync(currentFileName, saveDocumentStream);

                if (fileSaverResult.IsSuccessful)
                {
                    string filePath = string.IsNullOrEmpty(fileSaverResult.FilePath)
                        ? "Path information is not available."
                        : fileSaverResult.FilePath;

                    await DisplayAlertAsync(
                        "File Saved",
                        $"The file is saved to:\n{filePath}",
                        "OK");
                }
                else
                {
                    await DisplayAlertAsync(
                        "Error",
                        fileSaverResult.Exception?.Message ?? "Save failed.",
                        "OK");
                }
            }

        }

        private void OnSignaturePanelClicked(object? sender, EventArgs? e)
        {
            pdfViewer.DigitalSignatureSettings.IsSignaturePanelVisible = !pdfViewer.DigitalSignatureSettings.IsSignaturePanelVisible;
        }

        private void OnSignatureApplied(object? sender, SignatureDialogEventArgs? e)
        {
            if (e == null)
            {
                return;
            }
            if (e.CertificateStream == null || string.IsNullOrEmpty(e.CertificatePassword))
            {
                Application.Current!.Windows[0].Page!.DisplayAlertAsync("Error", "Please select a certificate and enter the password.", "OK");
                return;
            }
            CertificateStream = e.CertificateStream;
            CertificatePassword = e.CertificatePassword;
            Location = e.Location;
            Reason = e.Reason;
            ContactInfo = e.ContactInfo;
        }

        private void PdfViewer_DigitalSignatureModalViewAppearing(object? sender, DigitalSignatureModalViewAppearingEventArgs e)
        {
            // Use the user-selected certificate if one was picked; otherwise fall back
            // to the certificate.pfx bundled with the SampleBrowser.
            Stream? certificateStream = CertificateStream;
            string? certificatePassword = CertificatePassword;

            if (certificateStream == null || string.IsNullOrWhiteSpace(certificatePassword))
            {
                certificateStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Component.Resources.Pdf.certificate.pfx");
                certificatePassword = DefaultCertificatePassword;
            }

            e.Options = new SigningOptions
            {
                SignatureField = e.SignatureField,
                CertificateStream = certificateStream,
                CertificatePassword = certificatePassword,
                Reason = Reason,
                LocationInfo = Location,
                ContactInfo = ContactInfo,
                DigestAlgorithm = DigestAlgorithm.SHA256,
                CryptographicStandard = CryptographicStandard.CADES,
                Appearance = new SignatureAppearanceSettings
                {
                    ShowSignerName = true,
                    ShowDate = true,
                    ShowReason = true,
                    ShowLocation = true
                }
            };

        }

        /// <summary>
        /// Handles when leaving the current page
        /// </summary>
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            pdfViewer?.UnloadDocument();
            pdfViewer?.Handler?.DisconnectHandler();
        }

        private async void OnOpenClicked(object? sender, EventArgs? e)
        {
            // Define platform-specific file types for the file picker.
            FilePickerFileType pdfFileType = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>{
                    { DevicePlatform.iOS, new[] { "com.adobe.pdf" } },
                    { DevicePlatform.Android, new[] { "application/pdf" } },
                    { DevicePlatform.WinUI, new[] { "pdf" } },
                    { DevicePlatform.MacCatalyst, new[] { "pdf" } },
                });

            // Configure the file picker options.
            PickOptions options = new()
            {
                PickerTitle = "Choose a PDF file",
                FileTypes = pdfFileType,
            };

            // Launch the file picker and wait for user selection.
            var result = await FilePicker.Default.PickAsync(options);

            // Check if a file was selected.
            if (result != null)
            {
                // Ensure the file has a name.
                if (result.FileName != null)
                {
                    // Validate the file extension (case-insensitive).
                    if (result.FileName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
                    {
                        currentFileName = result.FileName;
                        // Get the stream.
                        Stream pdfStream = await result.OpenReadAsync();

                        // Load the Pdf in the PdfViewer control using LoadDocument method
                        pdfViewer.LoadDocument(pdfStream);
                    }
                }
            }

        }

        private void OnDigitalSignatureClicked(object? sender, EventArgs? e)
        {
            SignatureDialogControl.IsVisible = true;
        }

        private async void OnSaveClicked(object? sender, EventArgs? e)
        {
            // Create a new memory stream to hold the saved PDF document
            Stream saveDocumentStream = new MemoryStream();

            // Asynchronously save the current document content into the memory stream
            await pdfViewer.SaveDocumentAsync(saveDocumentStream);
            saveDocumentStream.Position = 0;

            // Save the pdf in the local storage using SaveAsync method in the `FileSaver` class present in the CommunityToolkit.Maui source.

            if (!string.IsNullOrEmpty(currentFileName))
            {
                var fileSaverResult = await FileSaver.Default.SaveAsync(currentFileName, saveDocumentStream);

                if (fileSaverResult.IsSuccessful)
                {
                    string filePath = string.IsNullOrEmpty(fileSaverResult.FilePath)
                        ? "Path information is not available."
                        : fileSaverResult.FilePath;

                    await DisplayAlertAsync(
                        "File Saved",
                        $"The file is saved to:\n{filePath}",
                        "OK");
                }
                else
                {
                    await DisplayAlertAsync(
                        "Error",
                        fileSaverResult.Exception?.Message ?? "Save failed.",
                        "OK");
                }
            }

        }

        private void OnSignaturePanelClicked(object? sender, EventArgs? e)
        {
            pdfViewer.DigitalSignatureSettings.IsSignaturePanelVisible = !pdfViewer.DigitalSignatureSettings.IsSignaturePanelVisible;
        }

        private async void OnSelectCertificateClicked(object? sender, EventArgs e)
        {
            try
            {
                var result = await FilePicker.PickAsync(new PickOptions
                {
                    PickerTitle = "Select Certificate File"
                });

                if (result == null)
                    return;

                _certificateStream = await result.OpenReadAsync();
                if (result.FileName.EndsWith(".pfx", StringComparison.OrdinalIgnoreCase) ||
                    result.FileName.EndsWith(".p12", StringComparison.OrdinalIgnoreCase))
                {
                    CertificateFileName.Text = result.FileName;
                    SetCertificateError(null);
                }
                else
                {
                    SetCertificateError("Invalid file selected");
                    _certificateStream = null;
                }
            }
            catch (Exception ex)
            {
                await DisplayAlertAsync("Error", $"Failed to select certificate: {ex.Message}", "OK");
            }
        }

        private void OnCancelClicked(object? sender, EventArgs e)
        {
            ResetForm();
            SignatureDialogControl.IsVisible = false;
        }

        private void OnCloseDialogClicked(object? sender, EventArgs e)
        {
            ResetForm();
            SignatureDialogControl.IsVisible = false;
        }

        private void PasswordEntry_TextChanged(object? sender, TextChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(PasswordEntry.Text))
                SetPasswordError(null);
        }

        private async void OnApplySignatureClicked(object? sender, EventArgs e)
        {
            SetCertificateError(null);
            SetPasswordError(null);

            var isValid = true;
            if (_certificateStream == null)
            {
                SetCertificateError("Please select a certificate file.");
                isValid = false;
            }

            if (string.IsNullOrWhiteSpace(PasswordEntry.Text))
            {
                SetPasswordError("Please enter the certificate password.");
                isValid = false;
            }

            if (!isValid)
                return;

            try
            {
                CertificateStream = _certificateStream;
                CertificatePassword = PasswordEntry.Text;
                Location = LocationEntry.Text?.Trim();
                Reason = ReasonEntry.Text?.Trim();
                ContactInfo = ContactInfoEntry.Text?.Trim();

                ResetForm();
                SignatureDialogControl.IsVisible = false;
            }
            catch (Exception ex)
            {
                await DisplayAlertAsync("Validation Error", $"Error applying signature: {ex.Message}", "OK");
            }
        }

        private void SetCertificateError(string? message)
        {
            if (message == null)
            {
                CertificateFileName.TextColor = Color.FromArgb("#666666");
            }
            else
            {
                CertificateFileName.Text = message;
                CertificateFileName.TextColor = Color.FromArgb("#B3261E");
            }
        }

        private void SetPasswordError(string? message)
        {
            PasswordErrorLabel.Text = message ?? string.Empty;
            PasswordErrorLabel.IsVisible = !string.IsNullOrEmpty(message);
        }

        private void ResetForm()
        {
            _certificateStream = null;
            CertificateFileName.TextColor = Color.FromArgb("#666666");
            CertificateFileName.Text = "No certificate selected";
            SetPasswordError(null);
            PasswordEntry.Text = string.Empty;
            LocationEntry.Text = string.Empty;
            ReasonEntry.Text = string.Empty;
            ContactInfoEntry.Text = string.Empty;
            passwordInputLayout.Unfocus();
            locationInputLayout.Unfocus();
            reasonInputLayout.Unfocus();
            contactinfoInputLayout.Unfocus();
            passwordInputLayout.ShowHint = true;
            locationInputLayout.ShowHint = true;
            reasonInputLayout.ShowHint = true;
            contactinfoInputLayout.ShowHint = true;
        }

        private void PasswordEntry_Focused(object? sender, FocusEventArgs e)
        {
            passwordInputLayout.ShowHint = false;
        }

        private void PasswordEntry_Unfocused(object? sender, FocusEventArgs e)
        {
            if (string.IsNullOrEmpty(PasswordEntry.Text))
                passwordInputLayout.ShowHint = true;
        }

        private void LocationEntry_Focused(object? sender, FocusEventArgs e)
        {
            locationInputLayout.ShowHint = false;
        }

        private void LocationEntry_Unfocused(object? sender, FocusEventArgs e)
        {
            if (string.IsNullOrEmpty(LocationEntry.Text))
                locationInputLayout.ShowHint = true;
        }

        private void ReasonEntry_Focused(object? sender, FocusEventArgs e)
        {
            reasonInputLayout.ShowHint = false;
        }

        private void ReasonEntry_Unfocused(object? sender, FocusEventArgs e)
        {
            if (string.IsNullOrEmpty(ReasonEntry.Text))
                reasonInputLayout.ShowHint = true;
        }

        private void ContactInfoEntry_Focused(object? sender, FocusEventArgs e)
        {
            contactinfoInputLayout.ShowHint = false;
        }

        private void ContactInfoEntry_Unfocused(object? sender, FocusEventArgs e)
        {
            if (string.IsNullOrEmpty(ContactInfoEntry.Text))
                contactinfoInputLayout.ShowHint = true;
        }

    }
}

```
