Skip to content

This repository contains a control for .NET MAUI and allows you to display PDF in View

License

Notifications You must be signed in to change notification settings

vitalii-vov/Maui.PDFView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maui.PDFView

Library for display PDF files in .NET MAUI on Android and iOS (Windows alpha)

maui-pdfview-480.mp4

.NET 8.0 .NET MAUI

Platform Supported
Android
iOS
MacOS
Windows

Installation

Install-Package Vitvov.Maui.PDFView

Usage

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseMauiPdfView()   // <- Write this
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
        return builder.Build();
    }
}
<ContentPage
    x:Class="Example.Business.UI.Pages.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:pdf="clr-namespace:Maui.PDFView;assembly=Maui.PDFView">

    <!--
    IsHorizontal — Display PDF horizontally
    Uri — Path to the file on the device
    MaxZoom — Max zoom level
    PageChangedCommand — event of changing the current page
    -->
    <pdf:PdfView
        IsHorizontal="{Binding IsHorizontal}"
        Uri="{Binding PdfSource}"
        MaxZoom="4"
        PageChangedCommand="{Binding PageChangedCommand}"/>

</ContentPage>
internal partial class MainPageViewModel : ObservableObject
{
    [ObservableProperty] private string _pdfSource;

    [RelayCommand] private void ChangeUri()
    {
        try 
        {
            //  See the example project to understand how to work with paths.
            PdfSource = "/path/to/file.pdf";
        }
        catch(Exception ex)
        {
             // handle exceptions
        }
    }
}