### Complete PDF Viewer Example (C#) Source: https://github.com/theeightbot/mauinativepdfview/blob/main/README.md This C# code provides the logic for the PDF viewer UI. It initializes the viewer with a sample PDF, handles page changes, link taps, errors, and implements toolbar button actions for navigation and zoom. ```csharp public partial class PdfPage : ContentPage { public PdfPage() { InitializeComponent(); pdfViewer.Source = PdfSource.FromAsset("sample.pdf"); } private void OnDocumentLoaded(object sender, DocumentLoadedEventArgs e) { statusLabel.Text = $"Loaded: {e.PageCount} pages - {e.Title}"; } private void OnPageChanged(object sender, PageChangedEventArgs e) { statusLabel.Text = $"Page {e.PageIndex + 1} of {e.PageCount}"; } private void OnLinkTapped(object sender, LinkTappedEventArgs e) { if (e.Uri != null) { // Intercept and handle external link yourself DisplayAlert("Link Tapped", $"Opening: {e.Uri}", "OK"); Launcher.OpenAsync(e.Uri); // Prevent default navigation e.Handled = true; } else if (e.DestinationPage.HasValue) { // Internal link - allow default navigation // Or set e.Handled = true to prevent it } } private void OnError(object sender, PdfErrorEventArgs e) { DisplayAlert("Error", e.Message, "OK"); } private void OnPreviousPage(object sender, EventArgs e) { if (pdfViewer.CurrentPage > 0) pdfViewer.GoToPage(pdfViewer.CurrentPage - 1); } private void OnNextPage(object sender, EventArgs e) { if (pdfViewer.CurrentPage < pdfViewer.PageCount - 1) pdfViewer.GoToPage(pdfViewer.CurrentPage + 1); } private void OnZoomIn(object sender, EventArgs e) { pdfViewer.Zoom = Math.Min(pdfViewer.Zoom + 0.5f, pdfViewer.MaxZoom); } private void OnZoomOut(object sender, EventArgs e) { pdfViewer.Zoom = Math.Max(pdfViewer.Zoom - 0.5f, pdfViewer.MinZoom); } } ``` -------------------------------- ### Add MauiNativePdfView NuGet Package Source: https://github.com/theeightbot/mauinativepdfview/blob/main/README.md Install the MauiNativePdfView package using the .NET CLI. Ensure you are using .NET 9.0 or later. ```bash dotnet add package MauiNativePdfView ``` -------------------------------- ### Complete PDF Viewer Example (XAML) Source: https://github.com/theeightbot/mauinativepdfview/blob/main/README.md This XAML defines the UI for a complete PDF viewer, including a toolbar for navigation and zoom, the PdfView control itself, and a status bar to display information. ```xml