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