![]() |
VOOZH | about |
Syncfusion AI Assistant
26 Jun 202621 minutes to read
This section guides you through setting up and configuring the PDF Viewer in your .NET MAUI application. Follow the steps below to add the PDF Viewer to your project and load a PDF document.
To get started quickly, you can also check out our video tutorial below.
Before proceeding, ensure the following are in place:
Syncfusion.Maui.Core is automatically installed as a dependency when Syncfusion.Maui.PdfViewer NuGet is installed.
MauiProgram.cs file.using Syncfusion.Maui.Core.Hosting;MauiProgram.cs file to use Syncfusion controls.public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
builder.ConfigureSyncfusionCore();
return builder.Build();
}Open the MainPage.xaml file and follow the steps below.
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"<syncfusion:SfPdfViewer x:Name="pdfViewer"></syncfusion:SfPdfViewer>Assets and add the PDF document you need to load into the PDF viewer. Here, a PDF document named PDF_Succinctly.pdf is used.Build Action as Embedded Resource.PdfViewerViewModel.cs and add the following code snippet.using System.ComponentModel;
using System.Reflection;
internal class PdfViewerViewModel : INotifyPropertyChanged
{
private Stream pdfDocumentStream;
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// Gets or sets the stream of the currently loaded PDF document.
/// </summary>
public Stream PdfDocumentStream
{
get
{
return pdfDocumentStream;
}
set
{
pdfDocumentStream = value;
OnPropertyChanged(nameof(PdfDocumentStream));
}
}
/// <summary>
/// Initializes a new instance of the <see cref="PdfViewerViewModel"/> class.
/// </summary>
public PdfViewerViewModel()
{
// Load the embedded PDF document stream.
// Replace 'PdfViewerExample' with your project's namespace in resource path
pdfDocumentStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("PdfViewerExample.Assets.PDF_Succinctly.pdf");
}
/// <summary>
/// Raises the <see cref="PropertyChanged"/> event for the specified property name.
/// </summary>
/// <param name="name">The name of the property that changed.</param>
public void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}MainPage.xaml file again and add the namespace PdfViewerExample and name it as local.xmlns:local="clr-namespace:PdfViewerExample"PdfViewerViewModel class as the BindingContext. Bind the PDF viewer’s DocumentSource to the PdfDocumentStream property of the PdfViewerViewModel class.<ContentPage.BindingContext>
<local:PdfViewerViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfPdfViewer x:Name="pdfViewer" DocumentSource="{Binding PdfDocumentStream}"/>NOTE
- While changing or opening different documents on the same page, the previously loaded document will be unloaded automatically by the SfPdfViewer.
- If you are using multiple pages in your application, then make sure to unload the document from the SfPdfViewer while leaving the page that has it to release the memory and resources consumed by the PDF document that is loaded. The unloading of documents can be done by calling the UnloadDocument method.
F5 to run the application.Before proceeding, ensure the following are in place:
Ctrl+Shift+P and type .NET:New Project and enter.Syncfusion.Maui.Core will be automatically installed as a dependency when Syncfusion.Maui.PdfViewer NuGet is installed.
MauiProgram.cs file.using Syncfusion.Maui.Core.Hosting;MauiProgram.cs file to use Syncfusion controls.public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
builder.ConfigureSyncfusionCore();
return builder.Build();
}Open the MainPage.xaml file and follow the steps below.
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"<syncfusion:SfPdfViewer x:Name="pdfViewer"></syncfusion:SfPdfViewer>Assets and add the PDF document you need to load into the PDF viewer. Here, a PDF document named PDF_Succinctly.pdf is used..csproj file and add the following code snippet to embed the PDF document as a resource.<ItemGroup>
<EmbeddedResource Include="Assets\PDF_Succinctly.pdf" />
</ItemGroup>PdfViewerViewModel.cs and add the following code snippet.using System.ComponentModel;
using System.Reflection;
internal class PdfViewerViewModel : INotifyPropertyChanged
{
private Stream pdfDocumentStream;
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// Gets or sets the stream of the currently loaded PDF document.
/// </summary>
public Stream PdfDocumentStream
{
get
{
return pdfDocumentStream;
}
set
{
pdfDocumentStream = value;
OnPropertyChanged(nameof(PdfDocumentStream));
}
}
/// <summary>
/// Initializes a new instance of the <see cref="PdfViewerViewModel"/> class.
/// </summary>
public PdfViewerViewModel()
{
// Load the embedded PDF document stream.
// Replace 'PdfViewerExample' with your project's namespace in resource path
pdfDocumentStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("PdfViewerExample.Assets.PDF_Succinctly.pdf");
}
/// <summary>
/// Raises the <see cref="PropertyChanged"/> event for the specified property name.
/// </summary>
/// <param name="name">The name of the property that changed.</param>
public void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}MainPage.xaml file again and add the namespace PdfViewerExampleand name it as local.xmlns:local="clr-namespace:PdfViewerExample"PdfViewerViewModel class as the BindingContext. Bind the PDF viewer’s DocumentSource to the PdfDocumentStream property of the PdfViewerViewModel class.<ContentPage.BindingContext>
<local:PdfViewerViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfPdfViewer x:Name="pdfViewer" DocumentSource="{Binding PdfDocumentStream}"/>NOTE
- While changing or opening different documents on the same page, the previously loaded document will be unloaded automatically by the SfPdfViewer.
- If you are using multiple pages in your application, then make sure to unload the document from the SfPdfViewer while leaving the page that has it to release the memory and resources consumed by the PDF document that is loaded. The unloading of documents can be done by calling the UnloadDocument method.
F5 to run the application.Before proceeding, ensure the following are set up:
dotnet restoreSyncfusion.Maui.Core is a dependency for all MAUI Syncfusion controls. This package will be automatically installed as a dependency when Syncfusion.Maui.PdfViewer NuGet is installed.
MauiProgram.cs file.using Syncfusion.Maui.Core.Hosting;MauiProgram.cs file to use Syncfusion controls.public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
builder.ConfigureSyncfusionCore();
return builder.Build();
}Open the MainPage.xaml file and follow the steps below.
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"pdfViewer.<syncfusion:SfPdfViewer x:Name="pdfViewer"></syncfusion:SfPdfViewer>Assets and add the PDF document you need to load into the PDF viewer. Here, a PDF document named PDF_Succinctly.pdf is used..csproj file and add the following code snippet to embed the PDF document as a resource.<ItemGroup>
<EmbeddedResource Include="Assets\PDF_Succinctly.pdf" />
</ItemGroup>PdfViewerViewModel.cs and add the following code snippet.using System.ComponentModel;
using System.Reflection;
internal class PdfViewerViewModel : INotifyPropertyChanged
{
private Stream pdfDocumentStream;
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// Gets or sets the stream of the currently loaded PDF document.
/// </summary>
public Stream PdfDocumentStream
{
get
{
return pdfDocumentStream;
}
set
{
pdfDocumentStream = value;
OnPropertyChanged(nameof(PdfDocumentStream));
}
}
/// <summary>
/// Initializes a new instance of the <see cref="PdfViewerViewModel"/> class.
/// </summary>
public PdfViewerViewModel()
{
// Load the embedded PDF document stream.
// Replace 'PdfViewerExample' with your project's namespace in resource path
pdfDocumentStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("PdfViewerExample.Assets.PDF_Succinctly.pdf");
}
/// <summary>
/// Raises the <see cref="PropertyChanged"/> event for the specified property name.
/// </summary>
/// <param name="name">The name of the property that changed.</param>
public void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}MainPage.xaml file again and add the namespace PdfViewerExample and name it as local.xmlns:local="clr-namespace:PdfViewerExample"PdfViewerViewModel class as the BindingContext. Bind the PDF viewer’s DocumentSource to the PdfDocumentStream property of the PdfViewerViewModel class.<ContentPage.BindingContext>
<local:PdfViewerViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfPdfViewer x:Name="pdfViewer" DocumentSource="{Binding PdfDocumentStream}"/>NOTE
- While changing or opening different documents on the same page, the previously loaded document will be unloaded automatically by the SfPdfViewer.
- If you are using multiple pages in your application, then make sure to unload the document from the SfPdfViewer while leaving the page that has it to release the memory and resources consumed by the PDF document that is loaded. The unloading of documents can be done by calling the UnloadDocument method.
👁 Getting started with .NET MAUI PDF Viewer
The Getting Started example project for the .NET MAUI PDF Viewer can be downloaded here.
NOTE
You can refer to our .NET MAUI PDF Viewer feature tour page for its groundbreaking feature representations. You can also explore our .NET MAUI PDF Viewer Example that shows you how to render the PDF Viewer in .NET MAUI.
Now that the PDF Viewer is running, you can explore the following features:
| Topics | Resources |
|---|---|
| Open documents from different sources | Load a PDF from a URL, the device’s file system, a Base64 string, or a password-protected file. → Open a Document |
| Navigate and read | Jump to specific pages, control zoom levels, and search for text. → Page Navigation · Magnification · Text Search |
| Add annotations | Highlight text, draw shapes, add sticky notes, or use freehand ink. → Annotations Overview |
| Fill form fields | Read, edit, validate, import, and export PDF form data. → Form Filling Overview |
| Save and print | Persist changes back to a file stream, optionally flattening annotations. → Save a Document · Print a Document |
| Customize the toolbar | Show, hide, add, or remove toolbar items to match your app’s workflow. → Toolbar Customization |
| Redact sensitive content | Permanently remove confidential text or images before sharing. → Redaction |