An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Maui.PDFView
Library for display PDF files in .NET MAUI on Android, iOS, MacOS and Windows

![NuGet Downloads](https://img.shields.io/nuget/dt/Vitvov.Maui.PDFView?style=for-the-badge)
![GitHub License](https://img.shields.io/github/license/vitalii-vov/Maui.PDFView?style=for-the-badge)
![last commit](https://img.shields.io/github/last-commit/vitalii-vov/Maui.PDFView?style=for-the-badge)

| .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.