Skip to content

PDFViewer - A simple Maui PDF viewer based on the nativ PDF libraries ...

License

Notifications You must be signed in to change notification settings

ZeProgFactory/PDFViewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

31/01/2026 - Work in progress ...

We were unable to get CollectionView to scroll horizontally properly, so we had to revert to a ScrollView. If anyone knows how to implement horizontal scrolling on CollectionView, we would appreciate your assistance. 😉

 

PDFViewer

A simple Maui PDF viewer based on the nativ PDF libraries ...
based on ideas and code of vitalii-vov ( https://github.com/vitalii-vov/Maui.PDFView )

“Powered by native PDF engines. Wrapped in simplicity.”


.NET MAUI .NET 10
Platform Android iOS Mac Windows
Supported (goal)
Progress 85 % 85 % 85 % 85 %

MacCatalyst is not tested yet!

NuGet Downloads   NuGet Downloads   GitHub License   last commit


iOS Android WinUI

Download

   https://www.nuget.org/packages/ZPF.PDFViewer.Maui

 

Installation

Install-Package ZPF.PDFViewer.Maui

or

dotnet add package ZPF.PDFViewer.Maui 

 

Installation

Install-Package ZPF.PDFViewer.Maui

 

Usage

Nothing to add to MauiProgram.

  Simply add PdfViewer to XAML

<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:ZPF.PDFViewer.Maui;assembly=PDFViewer.Maui">

   <pdf:PDFViewer                      
      IsToolbarVisible="True"
      BackgroundColor="AntiqueWhite"
      ToolbarColor="LightGray" 
      ClickOnPage="pdfViewer_ClickOnPage"
      DoubleClickOnPage="pdfViewer_DoubleClickOnPage" />

</ContentPage>

 

Set PDF source in code-behind

Load PDF from file path

   await pdfViewer.LoadPDF(fullPath);

Load PDF with password

   await pdfViewer.LoadPDF(fullPath, password);

For Android, Passwords are only supported on: 'android' 35.0 and later.

Error handling

   if (!await pdfViewer.LoadPDF(fullPath, password))
   {
      await DisplayAlertAsync("Oups ...", pdfViewer.LastMessage, "ok");
   }

 

Helper classes implementing IPdfSource

The PDFViewer component works only with file paths. This is because the native platform components primarily operate with file paths, and handling different PDF data sources directly inside the component would significantly complicate the code.

Therefore, you must always provide a file path regardless of the form your PDF data takes—whether it’s a file, an asset, or a URL.

To simplify working with these data sources, the component includes helper classes that implement the IPdfSource interface:

  • AssetPdfSource
  • FilePdfSource
  • HttpPdfSource

 

Load PDF from file path

   await pdfViewer.LoadPDF(new FilePdfSource(), FullPath);

Load PDF from URL

   await pdfViewer.LoadPDF(new HttpPdfSource(), "https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-download-10-mb.pdf");

Load PDF from resource asset

   await pdfViewer.LoadPDF(new AssetPdfSource(),"Example.Resources.PDF.pdf2.pdf");

See the example project to see the different sources in action.

You can also create your own implementation of the IPdfSource interface to address your specific needs.

 

Helper classe PDFToImageHelper

Methods to save PDF pages as images:

  • SaveFirstPageAsImageAsync(string pdfPath, string outputImagePath)
  • SavePageAsImageAsync(string pdfPath, string outputImagePath, uint pageNumber = 0)

  Example of using PDFToImageHelper

   {
      string tnFileName = System.IO.Path.GetTempFileName();

      await PDFToImageHelper.SaveFirstPageAsImageAsync(pdfFilepath, tnFileName);

      return tnFileName;
   }

 

Experimental doc...

 

About

PDFViewer - A simple Maui PDF viewer based on the nativ PDF libraries ...

Resources

License

Stars

Watchers

Forks

Packages

No packages published