https://github.com/vitalii-vov/Maui.PDFView
This repository contains a control for .NET MAUI and allows you to display PDF in View
https://github.com/vitalii-vov/Maui.PDFView
maui pdf pdfview pdfviewer
Last synced: 4 months ago
JSON representation
This repository contains a control for .NET MAUI and allows you to display PDF in View
- Host: GitHub
- URL: https://github.com/vitalii-vov/Maui.PDFView
- Owner: vitalii-vov
- License: mit
- Created: 2023-12-22T17:14:57.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-06-26T21:56:23.000Z (4 months ago)
- Last Synced: 2025-06-26T23:08:10.856Z (4 months ago)
- Topics: maui, pdf, pdfview, pdfviewer
- Language: C#
- Homepage:
- Size: 1.53 MB
- Stars: 48
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-dotnet-maui - Maui.PDFView - vov/Maui.PDFView?style=flat-square)](https://github.com/vitalii-vov/Maui.PDFView/stargazers)|[](https://github.com/vitalii-vov/Maui.PDFView/commits) (UI)
README
# Maui.PDFView
Library for display PDF files in .NET MAUI on Android, iOS, MacOS and Windows



| .NET MAUI | .NET 8 | .NET 9 |
| :-------- | :------- | :------- |
| Platform | Android | iOS | MacOS | Windows |
| :-------- | :----- | :-- | :---- | :------ |
| Supported | ✅ | ✅ | ✅ | ✅ |
https://github.com/vitalii-vov/Maui.PDFView/assets/71486507/4977ede8-c8db-454f-930d-ba2ec704f16d
## Installation
```
Install-Package Vitvov.Maui.PDFView
```
## Usage
Add `.UseMauiPdfView()` to MauiProgram
```C#
using Maui.PDFView;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
.UseMauiPdfView(); // <- Write this
return builder.Build();
}
}
```
Add `PdfView` to XAML
```xaml
```
> [!IMPORTANT]
> To use a component with `.net9` add `HandlerProperties.DisconnectPolicy="Manual"` to `PdfView`
> ```XAML
> HandlerProperties.DisconnectPolicy="Manual" />
> ```
Set `PdfSource` in ViewModel
```C#
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
}
}
}
```
## Personalization
You can customize the way pages are displayed by modifying the `PageAppearance` property in the `PdfView` component.
```xaml
```
## Helper classes implementing `IPdfSource`
The `PdfView` 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 byte array, a stream, an asset, or a URL.
To simplify working with these data sources, the component includes helper classes that implement the `IPdfSource` interface:
- `AssetPdfSource`
- `ByteArrayPdfSource`
- `FilePdfSource`
- `HttpPdfSource`
Example of using PdfSource
```C#
[RelayCommand] private async Task UploadUri()
{
var source = new HttpPdfSource("https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf");
PdfSource = await source.GetFilePathAsync();
}
[RelayCommand] private async Task UploadAsset()
{
var source = new AssetPdfSource("Example.Resources.PDF.pdf2.pdf");
PdfSource = await source.GetFilePathAsync();
}
```
You can also create your own implementation of the `IPdfSource` interface to address your specific needs.