{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "pdf-viewer-custom-toolbar",
  "framework": "maui",
  "type": "registry:component",
  "component": "PdfViewer",
  "variant": "custom-toolbar",
  "dependencies": [
    "Syncfusion.Maui.PdfViewer"
  ],
  "description": "PDF viewer uses custom controls for document search, text markup annotations, and undo/redo.",
  "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-custom-toolbar.md"
  },
  "files": [
    {
      "target": "src/components/pdf-viewer-custom-toolbar/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.CustomToolbar\"\n             x:Class=\"MAUI.Controls.PdfViewer.CustomToolbar.PdfViewerView\"\n             x:DataType=\"model:PdfViewerViewModel\"\n             Title=\"PDF Viewer - Custom Toolbar\">\n    <ContentPage.Resources>\n        <Style TargetType=\"Button\">\n            <Setter Property=\"BorderWidth\"\n                    Value=\"0\"/>\n            <Setter Property=\"FontSize\"\n                    Value=\"18\"/>\n            <Setter Property=\"Padding\"\n                    Value=\"4\"/>\n            <Setter Property=\"VerticalOptions\"\n                    Value=\"Center\"/>\n            <Setter Property=\"FontFamily\"\n                    Value=\"{OnPlatform iOS=PdfViewerIcon, MacCatalyst=PdfViewerIcon, Android=PdfViewerIcon.ttf#, WinUI=PdfViewerIcon.ttf#PdfViewerIcon}\"/>\n            <Setter Property=\"VisualStateManager.VisualStateGroups\">\n                <VisualStateGroupList>\n                    <VisualStateGroup x:Name=\"CommonStates\">\n                        <VisualState x:Name=\"Normal\">\n                            <VisualState.Setters>\n                                <Setter Property=\"TextColor\"\n                                        Value=\"#99000000\"/>\n                                <Setter Property=\"BackgroundColor\"\n                                        Value=\"Transparent\"/>\n                            </VisualState.Setters>\n                        </VisualState>\n                        <VisualState x:Name=\"Disabled\">\n                            <VisualState.Setters>\n                                <Setter Property=\"TextColor\"\n                                        Value=\"#44000000\"/>\n                                <Setter Property=\"BackgroundColor\"\n                                        Value=\"Transparent\"/>\n                            </VisualState.Setters>\n                        </VisualState>\n                        <VisualState x:Name=\"Pressed\">\n                            <VisualState.Setters>\n                                <Setter Property=\"TextColor\"\n                                        Value=\"#99000000\"/>\n                                <Setter Property=\"BackgroundColor\"\n                                        Value=\"#0F000000\"/>\n                            </VisualState.Setters>\n                        </VisualState>\n                    </VisualStateGroup>\n                </VisualStateGroupList>\n            </Setter>\n        </Style>\n    </ContentPage.Resources>\n    <ContentPage.Content>\n        <Grid>\n            <Grid.RowDefinitions>\n                <RowDefinition Height=\"Auto\"/>\n                <RowDefinition Height=\"Auto\"/>\n                <RowDefinition Height=\"*\"/>\n            </Grid.RowDefinitions>\n            <Grid Grid.Row=\"0\"\n                    HeightRequest=\"40\"\n                    BackgroundColor=\"#FFF6F6F6\">\n                <Grid.ColumnDefinitions>\n                    <ColumnDefinition Width=\"{OnPlatform Default=Auto, Android=1.5*, iOS=1.5*}\"/>\n                    <ColumnDefinition Width=\"{OnPlatform Default=*, Android=3*, iOS=3*}\"/>\n                    <ColumnDefinition Width=\"{OnPlatform Default=*, Android=1*, iOS=1*}\"/>\n                    <ColumnDefinition Width=\"{OnPlatform Default=60, Android=1*, iOS=1*}\"/>\n                </Grid.ColumnDefinitions>\n                <HorizontalStackLayout Spacing=\"10\"\n                        Grid.Column=\"0\"\n                        Margin=\"8,0,0,0\"\n                        HorizontalOptions=\"Start\">\n                    <Button Text=\"&#xe700;\"\n                            FontFamily=\"MauiMaterialAssets\"\n                            PropertyChanged=\"Button_PropertyChanged\"\n                            Command=\"{Binding OpenFileCommand}\"\n                            IsVisible=\"{OnPlatform MacCatalyst=false}\"/>\n                    <Button Text=\"&#xe77f;\"\n                            FontSize=\"20\"\n                            FontFamily=\"MauiMaterialAssets\"\n                            Command=\"{Binding Source={x:Reference PdfViewer},Path=PrintDocumentCommand}\"/>\n                </HorizontalStackLayout>\n                <HorizontalStackLayout HorizontalOptions=\"{OnPlatform Default=End, Android=CenterAndExpand, iOS=CenterAndExpand}\"\n                                       Spacing=\"8\"\n                        Grid.Column=\"1\">\n                    <Border BackgroundColor=\"#FFFFFFFF\"\n                            Stroke=\"#66000000\"\n                            StrokeShape=\"{OnPlatform Default=RoundRectangle 4, MacCatalyst=RoundRectangle 5, iOS=RoundRectangle 5}\"\n                            HeightRequest=\"{OnPlatform Android=30,WinUI=34, MacCatalyst=26, iOS=26}\"\n                            Padding=\"{OnPlatform Android=5}\"\n                            StrokeThickness=\"1\">\n                        <Entry\n                            x:Name=\"PageNumberEntry\"\n                            Text=\"{Binding PageNumber}\"\n                            MaxLength=\"4\"\n                            Keyboard=\"Numeric\"\n                            VerticalTextAlignment=\"Center\"\n                            WidthRequest=\"40\"\n                            HeightRequest=\"{OnPlatform Default=24, Android=40}\"\n                            TextChanged=\"PageNumberEntry_TextChanged\"\n                            Unfocused=\"PageNumberEntry_Unfocused\"\n                            Completed=\"PageNumberEntry_Completed\"\n                            VerticalOptions=\"Center\"\n                            HorizontalTextAlignment=\"Center\"/>\n                    </Border>\n                    <Label\n                        Text=\" / \"\n                        VerticalTextAlignment=\"Center\"\n                        HorizontalTextAlignment=\"Center\"\n                        VerticalOptions=\"Center\"/>\n                    <Label\n                        Text=\"{Binding PageCount}\"\n                        VerticalTextAlignment=\"Center\"\n                        HorizontalTextAlignment=\"Center\"\n                        VerticalOptions=\"Center\"\n                        Margin=\"0,0,4,0\"/>\n                    <Button\n                        Text=\"&#xe702;\"\n                            FontSize=\"16\"\n                        FontFamily=\"MauiMaterialAssets\"\n                        PropertyChanged=\"Button_PropertyChanged\"\n                        Margin=\"4,0,0,0\"\n                            IsEnabled=\"{Binding CanGoToPreviousPage}\"\n                        Command=\"{Binding Source={x:Reference PdfViewer},Path=GoToPreviousPageCommand}\"/>\n                    <Button\n                        Text=\"&#xe701;\"\n                            FontSize=\"16\"\n                        FontFamily=\"MauiMaterialAssets\"\n                        PropertyChanged=\"Button_PropertyChanged\"\n                        Margin=\"4,0,0,0\"\n                            IsEnabled=\"{Binding CanGoToNextPage}\"\n                        Command=\"{Binding Source={x:Reference PdfViewer},Path=GoToNextPageCommand}\"/>\n                    <Rectangle Fill=\"#FF979797\"\n                            HeightRequest=\"24\"\n                            WidthRequest=\"2\"/>\n                </HorizontalStackLayout>\n                <HorizontalStackLayout\n                    Grid.Column=\"2\"\n                        Margin=\"8,0,12,0\"\n                    HorizontalOptions=\"{OnPlatform MacCatalyst=Start, iOS=End, Android=End, WinUI=Start}\">\n                    <Button\n                        Text=\"&#xe704;\"\n                            Margin=\"4,0,0,0\"\n                        FontFamily=\"MauiMaterialAssets\"\n                        Command=\"{Binding ZoomOutCommand}\"\n                            IsEnabled=\"{Binding CanZoomOut}\"\n                        PropertyChanged=\"Button_PropertyChanged\"/>\n                    <Button\n                        Text=\"&#xe703;\"\n                            Margin=\"4,0,0,0\"\n                        FontFamily=\"MauiMaterialAssets\"\n                        Command=\"{Binding ZoomInCommand}\"\n                            IsEnabled=\"{Binding CanZoomIn}\"\n                        PropertyChanged=\"Button_PropertyChanged\"/>\n                </HorizontalStackLayout>\n                <Grid Grid.Column=\"3\"\n                        Margin=\"0,0,12,0\"\n                        HorizontalOptions=\"End\">\n                    <Button Text=\"&#xe795;\"\n                            Margin=\"0,0,0,0\"\n                            HorizontalOptions=\"End\"\n                            FontFamily=\"MauiMaterialAssets\"\n                            PropertyChanged=\"Button_PropertyChanged\"\n                            Clicked=\"pageLayoutClicked\"/>\n                </Grid>\n            </Grid>\n            <Line Grid.Row=\"1\"\n                    StrokeThickness=\"1\"\n                    BackgroundColor=\"#33000000\"/>\n            <syncfusion:SfPdfViewer\n                x:Name=\"PdfViewer\"\n                Grid.Row=\"2\"\n                ShowToolbars=\"False\"\n                PageCount=\"{Binding PageCount, Mode=OneWayToSource}\"\n                PageNumber=\"{Binding PageNumber, Mode=OneWayToSource}\"\n                MinZoomFactor=\"{Binding MinZoom, Mode=OneWayToSource}\"\n                MaxZoomFactor=\"{Binding MaxZoom, Mode=OneWayToSource}\"\n                DocumentSource=\"{Binding PdfDocumentStream}\"\n                ZoomFactor=\"{Binding CurrentZoom,Mode=TwoWay}\"\n                PasswordRequested=\"PdfViewer_PasswordRequested\"\n                DocumentLoadFailed=\"PdfViewer_DocumentLoadFailed\">\n            </syncfusion:SfPdfViewer>\n            <Grid x:Name=\"PasswordDialog\"\n                  Grid.Row=\"2\"\n                  WidthRequest=\"360\"\n                  HeightRequest=\"280\"\n                  Padding=\"16\"\n                  Background=\"White\"\n                  HorizontalOptions=\"Center\"\n                  VerticalOptions=\"Center\"\n                  IsVisible=\"False\">\n                <Grid.RowDefinitions>\n                    <RowDefinition Height=\"1*\"/>\n                    <RowDefinition Height=\"2*\"/>\n                    <RowDefinition Height=\"2*\"/>\n                    <RowDefinition Height=\"1*\"/>\n                    <RowDefinition Height=\"1*\"/>\n                </Grid.RowDefinitions>\n                <Label Grid.Row=\"0\"\n                       Text=\"Enter a Password\"\n                       FontAttributes=\"Bold\"\n                       FontSize=\"20\"\n                       VerticalOptions=\"Start\"/>\n                <Label Grid.Row=\"1\"\n                       Text=\"The file is protected. Please enter a password to open the PDF file.\"\n                       VerticalOptions=\"Center\"\n                       VerticalTextAlignment=\"End\"\n                       LineBreakMode=\"WordWrap\"/>\n                <VerticalStackLayout Grid.Row=\"2\"\n                        Spacing=\"2\">\n                    <Border Stroke=\"{OnPlatform Android=Gray}\"\n                            Padding=\"{OnPlatform Android=4}\">\n                        <Entry x:Name=\"PasswordEntry\"\n                               Placeholder=\"Password\"\n                               IsPassword=\"True\"\n                               TextChanged=\"PasswordEntry_TextChanged\"/>\n                    </Border>\n                    <Label x:Name=\"PasswordHelperText\"\n                           VerticalOptions=\"Center\"\n                           VerticalTextAlignment=\"Center\"\n                           LineBreakMode=\"WordWrap\"\n                           FontSize=\"12\"\n                           Padding=\"0,2,0,2\"/>\n                </VerticalStackLayout>\n                <HorizontalStackLayout Grid.Row=\"3\"\n                                       Spacing=\"8\"\n                                       VerticalOptions=\"Start\">\n                    <CheckBox x:Name=\"ShowPasswordCheckBox\"\n                              CheckedChanged=\"ShowPasswordCheckBox_CheckedChanged\"/>\n                    <Label Text=\"Show Password\"\n                           HorizontalTextAlignment=\"Center\"\n                           VerticalTextAlignment=\"Center\"/>\n                </HorizontalStackLayout>\n                <Grid Grid.Row=\"4\">\n                    <Grid.ColumnDefinitions>\n                        <ColumnDefinition Width=\"*\"/>\n                        <ColumnDefinition Width=\"Auto\"/>\n                        <ColumnDefinition Width=\"20\"/>\n                        <ColumnDefinition Width=\"Auto\"/>\n                    </Grid.ColumnDefinitions>\n                    <Button Grid.Column=\"1\"\n                            Text=\"CANCEL\"\n                            FontSize=\"14\"\n                            FontFamily=\"Roboto\"\n                            Padding=\"16,8\"\n                            Background=\"#512BD4\"\n                            TextColor=\"White\"\n                            Clicked=\"PasswordDialog_CancelClicked\"\n                            VerticalOptions=\"End\"/>\n                    <Button Grid.Column=\"3\"\n                            Text=\"OK\"\n                            FontSize=\"14\"\n                            FontFamily=\"Roboto\"\n                            Padding=\"16,8\"\n                            Background=\"#512BD4\"\n                            TextColor=\"White\"\n                            Clicked=\"PasswordDialog_OkClicked\"\n                            VerticalOptions=\"End\"/>\n                </Grid>\n            </Grid>\n            <Grid x:Name=\"MessageDialog\"\n                  Grid.Row=\"2\"\n                  WidthRequest=\"320\"\n                  HeightRequest=\"200\"\n                  HorizontalOptions=\"Center\"\n                  VerticalOptions=\"Center\"\n                  IsVisible=\"False\">\n                <Border Background=\"White\"\n                        Stroke=\"#33000000\"\n                        StrokeShape=\"RoundRectangle 4\"\n                        StrokeThickness=\"1\">\n                    <Grid Padding=\"20\">\n                        <Grid.RowDefinitions>\n                            <RowDefinition Height=\"1*\"/>\n                            <RowDefinition Height=\"2*\"/>\n                            <RowDefinition Height=\"1*\"/>\n                        </Grid.RowDefinitions>\n                        <Label x:Name=\"MessageTitle\"\n                               Grid.Row=\"0\"\n                               FontAttributes=\"Bold\"\n                               FontSize=\"20\"\n                               VerticalOptions=\"Start\"\n                               VerticalTextAlignment=\"Start\"/>\n                        <Label x:Name=\"MessageText\"\n                               Grid.Row=\"1\"\n                               TextColor=\"#DE000000\"\n                               VerticalTextAlignment=\"Center\"\n                               LineBreakMode=\"WordWrap\"/>\n                        <Button x:Name=\"MessageOkButton\"\n                                Grid.Row=\"2\"\n                                FontSize=\"14\"\n                                FontFamily=\"Roboto\"\n                                Padding=\"16,8\"\n                                Background=\"#512BD4\"\n                                TextColor=\"White\"\n                                Text=\"CLOSE\"\n                                Clicked=\"MessageBox_OKClicked\"\n                                HorizontalOptions=\"End\"\n                                VerticalOptions=\"End\"/>\n                    </Grid>\n                </Border>\n            </Grid>\n            <Grid x:Name=\"PageLayout\"\n                  Grid.Row=\"2\"\n                  WidthRequest=\"{OnPlatform MacCatalyst=205, iOS=150, Android=150, WinUI=205}\"\n                  HeightRequest=\"84\"\n                  HorizontalOptions=\"End\"\n                  VerticalOptions=\"Start\"\n                  IsVisible=\"False\">\n                <Border Background=\"#F7F2FB\"\n                        StrokeShape=\"RoundRectangle 4\"\n                        Padding=\"0\">\n                    <Grid RowDefinitions=\"*,*\">\n                        <Grid x:Name=\"ContinuousLayoutOption\"\n                              Grid.Row=\"0\"\n                              AutomationId=\"ContinuousLayoutOption\">\n                            <Grid.GestureRecognizers>\n                                <TapGestureRecognizer Tapped=\"ContinuousPageLayout_Tapped\"/>\n                            </Grid.GestureRecognizers>\n                            <HorizontalStackLayout Spacing=\"8\"\n                                                   Padding=\"8,0\"\n                                                   VerticalOptions=\"Center\">\n                                <Label Text=\"&#xE796;\"\n                                       FontSize=\"18\"\n                                       FontFamily=\"MauiMaterialAssets\"\n                                       TextColor=\"#212121\"\n                                       VerticalOptions=\"Center\"/>\n                                <Label Text=\"Continuous page\"\n                                       FontSize=\"{OnPlatform MacCatalyst=16, iOS=14, Android=14, WinUI=16}\"\n                                       FontFamily=\"Roboto\"\n                                       TextColor=\"#212121\"\n                                       VerticalOptions=\"Center\"/>\n                            </HorizontalStackLayout>\n                        </Grid>\n                        <Grid x:Name=\"SingleLayoutOption\"\n                              Grid.Row=\"1\"\n                              AutomationId=\"SingleLayoutOption\">\n                            <Grid.GestureRecognizers>\n                                <TapGestureRecognizer Tapped=\"SinglePageLayout_Tapped\"/>\n                            </Grid.GestureRecognizers>\n                            <HorizontalStackLayout Spacing=\"8\"\n                                                   Padding=\"8,0\"\n                                                   VerticalOptions=\"Center\">\n                                <Label Text=\"&#xE797;\"\n                                       FontSize=\"18\"\n                                       FontFamily=\"MauiMaterialAssets\"\n                                       TextColor=\"#212121\"\n                                       VerticalOptions=\"Center\"/>\n                                <Label Text=\"Page by page\"\n                                       FontSize=\"{OnPlatform MacCatalyst=16, iOS=14, Android=14, WinUI=16}\"\n                                       FontFamily=\"Roboto\"\n                                       TextColor=\"#212121\"\n                                       VerticalOptions=\"Center\"/>\n                            </HorizontalStackLayout>\n                        </Grid>\n                    </Grid>\n                </Border>\n            </Grid>\n        </Grid>\n    </ContentPage.Content>\n</ContentPage>\n"
    },
    {
      "target": "src/components/pdf-viewer-custom-toolbar/PdfViewer.xaml.cs",
      "content": "using Microsoft.Maui.Platform;\nusing Syncfusion.Maui.PdfViewer;\nnamespace MAUI.Controls.PdfViewer.CustomToolbar\n{\n    public partial class PdfViewerView : ContentPage\n    {\n        private int targetPageNumber = 0;\n        private bool pageNumberChanged = false;\n        //When loading password protected files, it is used to wait the current thread's execution, until the user enters the password.\n        private ManualResetEvent manualResetEvent = new ManualResetEvent(false);\n\n        public PdfViewerView(PdfViewerViewModel viewModel)\n        {\n            InitializeComponent();\n            BindingContext = viewModel;\n        }\n\n        /// <summary>\n        /// Handles automatic page number selection in the entry when the entry is tapped.\n        /// </summary>\n        private void PageNumberEntry_HandlerChanged(object sender, EventArgs e)\n        {\n            if (PageNumberEntry.Handler != null)\n            {\n                var handler = PageNumberEntry.Handler as Microsoft.Maui.Handlers.EntryHandler;\n#if ANDROID\n            handler.PlatformView.SetSelectAllOnFocus(true);\n#elif IOS || MACCATALYST\n        handler.PlatformView.EditingDidBegin += (s, e) =>\n        {\n            handler.PlatformView.PerformSelector(new ObjCRuntime.Selector(\"selectAll\"), null, 0.0f);\n        };\n#elif WINDOWS\n        handler.PlatformView.GotFocus += (s, e) =>\n        {\n            handler.PlatformView.SelectAll();\n        };\n#endif\n            }\n        }\n\n        /// <summary>\n        /// Handles the page number validation when the page number is typed in the entry.\n        /// </summary>\n        void PageNumberEntry_TextChanged(System.Object sender, Microsoft.Maui.Controls.TextChangedEventArgs e)\n        {\n            if (PageNumberEntry != null && PageNumberEntry.IsFocused && !string.IsNullOrEmpty(PageNumberEntry.Text))\n            {\n                bool isPageNumber = int.TryParse(PageNumberEntry.Text, out targetPageNumber);\n                if (isPageNumber)\n                {\n                    pageNumberChanged = true;\n                    PageNumberEntry.Text = targetPageNumber.ToString();\n                }\n                else\n                {\n                    PageNumberEntry.Text = e.OldTextValue;\n                }\n            }\n        }\n\n        /// <summary>\n        /// Handles when the page number entry focused property changes to unfocused.\n        /// </summary>\n        void PageNumberEntry_Unfocused(System.Object sender, Microsoft.Maui.Controls.FocusEventArgs e)\n        {\n            PageNumberEntry.Text = PdfViewer?.PageNumber.ToString();\n        }\n\n        /// <summary>\n        /// Handles when the page number is entered in the entry.\n        /// </summary>\n        private void PageNumberEntry_Completed(object sender, EventArgs e)\n        {\n            // When the enter key is pressed, the soft keyboard hides.\n#if ANDROID\n        if (Platform.CurrentActivity?.CurrentFocus != null)\n            Platform.CurrentActivity.HideKeyboard(Platform.CurrentActivity.CurrentFocus);\n#endif\n            if (pageNumberChanged && targetPageNumber != PdfViewer.PageNumber)\n            {\n                if (targetPageNumber > 0 && targetPageNumber <= PdfViewer.PageCount)\n                {\n                    PdfViewer.GoToPage(targetPageNumber);\n                    pageNumberChanged = false;\n\n                }\n                else\n                {\n                    // Shows the invalid page number to the user when trying to go to the entered page number when the loaded PDF document does not have a page number.\n                    MainThread.BeginInvokeOnMainThread(() =>\n                    {\n                        MessageBox.Show(\"Error\", \"Invalid Page Number\", \"OK\");\n                    });\n                    PageNumberEntry.Text = PdfViewer.PageNumber.ToString();\n                }\n                PageNumberEntry.Unfocus();\n            }\n        }\n\n        /// <summary>\n        /// Handles the button enable and disable states when the button property changes.\n        /// </summary>\n        private void Button_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)\n        {\n            if (sender is Button button)\n            {\n                if (e.PropertyName == \"IsEnabled\")\n                {\n                    if (!button.IsEnabled)\n                    {\n                        button.Unfocus();\n                    }\n                    else\n                    {\n                        Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(1), () =>\n                        {\n                            VisualStateManager.GoToState(button, \"Normal\");\n                        });\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Handles password requested event.\n        /// </summary>\n        private void PdfViewer_PasswordRequested(object sender, Syncfusion.Maui.PdfViewer.PasswordRequestedEventArgs e)\n        {\n            //Show the password dialog.\n            PasswordDialog.Dispatcher.Dispatch(() => PasswordDialog.IsVisible = true);\n\n            //Block the current thread until user enters the password.\n            manualResetEvent.WaitOne();\n            manualResetEvent.Reset();\n\n            //Pass the user password to PDF Viewer to validate and load the PDF.\n            e.Password = PasswordDialog.Password;\n            e.Handled = true;\n        }\n\n        /// <summary>\n        /// Handles when document is failed to load.\n        /// </summary>\n        private void PdfViewer_DocumentLoadFailed(object sender, Syncfusion.Maui.PdfViewer.DocumentLoadFailedEventArgs e)\n        {\n            //Show the incorrect password message to the user, when document failed to load if the password is invalid.\n            if (e.Message == \"Can't open an encrypted document. The password is invalid.\")\n            {\n                //Unloads the current document.\n                PdfViewer.DocumentSource = null;\n                MainThread.BeginInvokeOnMainThread(() => MessageBox.Show(\"Incorrect Password\", \"The password you entered is incorrect. Please try again.\"));\n            }\n            else if (e.Message == \"Invalid cross reference table.\")\n            {\n                //Show the error message to the user, when corrupted document is loaded.\n                MainThread.BeginInvokeOnMainThread(() => MessageBox.Show(\"Error\", \"Failed to load the PDF document.\"));\n                if (BindingContext is PdfViewerViewModel context)\n                {\n                    context.PdfDocumentStream = null;\n                }\n            }\n        }\n\n        private string Password { get; set; }\n\n        private void PasswordDialog_CancelClicked(object sender, EventArgs e)\n        {\n            Password = null;\n            PasswordEntry.Text = string.Empty;\n            PasswordDialog.IsVisible = false;\n            manualResetEvent.Set();\n        }\n\n        private void PasswordDialog_OkClicked(object sender, EventArgs e)\n        {\n            if (string.IsNullOrEmpty(PasswordEntry.Text))\n            {\n                PasswordHelperText.TextColor = Colors.Red;\n                PasswordHelperText.Text = \"* Password cannot be empty\";\n                return;\n            }\n\n            Password = PasswordEntry.Text;\n            PasswordEntry.Text = string.Empty;\n            PasswordDialog.IsVisible = false;\n            manualResetEvent.Set();\n        }\n\n        private void PasswordEntry_TextChanged(object sender, TextChangedEventArgs e)\n        {\n            if (!string.IsNullOrEmpty(e.NewTextValue))\n                PasswordHelperText.Text = string.Empty;\n        }\n\n        private void ShowPasswordCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)\n        {\n            PasswordEntry.IsPassword = !e.Value;\n        }\n\n        private void ShowMessage(string title, string message, string closeText = \"CLOSE\")\n        {\n            MessageTitle.Text = title;\n            MessageText.Text = message;\n            MessageOkButton.Text = closeText;\n            MessageDialog.IsVisible = true;\n        }\n\n        /// <summary>\n        /// Handles when the message box's ok button is clicked.\n        /// </summary>\n        private void MessageBox_OKClicked(object sender, EventArgs e)\n        {\n            MessageDialog.IsVisible = false;\n            if (BindingContext is PdfViewerViewModel context)\n            {\n                // Retry loading the document.\n                if (context.PdfDocumentStream != null)\n                    PdfViewer.DocumentSource = context.PdfDocumentStream;\n            }\n        }\n\n        /// <summary>\n        /// Toggles the visibility of the page layout options when the page layout button is clicked.\n        /// </summary>\n        private void pageLayoutClicked(object sender, EventArgs e)\n        {\n            PageLayout.IsVisible = !PageLayout.IsVisible;\n        }\n\n        /// <summary>\n        /// Handles the change of page layout mode based on user selection.\n        /// </summary>\n        private void ContinuousPageLayout_Tapped(object sender, TappedEventArgs e)\n        {\n            SetPageLayoutMode(PageLayoutMode.Continuous);\n        }\n\n        private void SinglePageLayout_Tapped(object sender, TappedEventArgs e)\n        {\n            SetPageLayoutMode(PageLayoutMode.Single);\n        }\n\n        private void SetPageLayoutMode(PageLayoutMode mode)\n        {\n            if (BindingContext is PdfViewerViewModel context)\n            {\n                context.PageLayoutMode = mode;\n                PdfViewer.PageLayoutMode = mode;\n                PageLayout.IsVisible = false;\n            }\n        }\n\n    }\n}\n"
    }
  ]
}