Getting started on MAUI

This guide will walk you through the steps necessary to integrate Nutrient MAUI SDK into your desktop or mobile project. By the end, you’ll be able to present a PDF document in the Nutrient UI.

Requirements

Creating a new project

  1. Open Visual Studio. Select Create a new project.

  1. In the new project wizard, select .NET MAUI App and click Next.

  1. Configure your project by setting the name and location, as shown in the image below.

  1. Specify the target framework. This example uses the default.

Adding Nutrient to your project

  1. Double-click the project name to access the project file. It will look similar to the image below.

  1. Change the first line from <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.Razor"> and save the project file.

  2. Open your app’s solution, and in the Solution Explorer, right-click on your project and click the Manage NuGet Packages… menu item. This will open the NuGet Package Manager for your solution.

  1. Search for PSPDFKit MAUI, and you’ll find the package on nuget.org.

  2. On the right side, in the panel describing the package, click Install to install the package.

  1. Once the package is installed, click MauiProgram.cs and call the RegisterPSPDFKitSdk() method on the builder. The resulting CreateMauiApp function will look like the following:

public static MauiApp CreateMauiApp()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()
        .RegisterPSPDFKitSdk() // added
        .ConfigureFonts(fonts =>
		{
			fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
			fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
		});

#if DEBUG
    builder.Logging.AddDebug();
#endif
    
    return builder.Build();
	}

Displaying a PDF

  1. In the Resources/Raw folder, create an Assets folder and add a PDF file named demo.pdf.

Note that this is a special folder and it has to be named Assets. PDFs located in this folder can be loaded in the application using a specially designed API, LoadDocumentFromAssetsAsync.

  1. Open MainPage.xaml, remove all the content of ContentPage, and paste the following XML as its content:

<pspdfkit:PDFView x:Name="PDFView" />
  1. You’ll see a green line under pspdfkit:PDFView. If you hover over it, you’ll be given the option for potential fixes. Apply the suggested fix, which will add the following namespace to <ContentPage>:

xmlns:pspdfkit="clr-namespace:PSPDFKit.Sdk;assembly=Sdk"
  1. If you’ve purchased a license and assigned it to a bundle ID, you can add it to the correct platform here:

<pspdfkit:PDFView x:Name="PDFView"
				  License="{OnPlatform 
				  	Android={StaticResource AndroidLicenseKey},
				  	iOS={StaticResource iOSLicenseKey},
				  	MacCatalyst={StaticResource MacCatalystLicenseKey},
				  	WinUI={StaticResource WindowsLicenseKey}}" />

If not, omitting the License property will initialize the PDFView in trial mode.

  1. To subscribe to the Initialized event of PDFView, add the following code to the MainPage.xaml and MainPage.xaml.cs files. In this event handler, use the PDFView.Controller.LoadDocumentFromAssetsAsync function to load the demo.pdf file that was added to the Assets folder:

<pspdfkit:PDFView x:Name="PDFView" Initialized="OnPDFViewInitialized" />
private async void OnPDFViewInitialized(object sender, EventArgs e)
{
	try
	{
		var configuration = PDFView.Controller.CreateViewerConfiguration();
		await PDFView.Controller.LoadDocumentFromAssetsAsync("demo.pdf", configuration);
	}
	catch (Exception ex)
	{
		// Handle exception.
	}
}

Note that you must wait for initialization of the PDFView to be complete before using PdfView.Controller.

  1. In the Build toolbar, choose Debug, and select the platform you’d like to build on — for example, x86 or x64.

  2. Then, in the menu, select Build > Build Solution.

  3. Start the application, and you’ll see demo.pdf loaded in PDFView.

This guide will walk you through the steps necessary to integrate Nutrient MAUI SDK into your desktop or mobile project. By the end, you’ll be able to present a PDF document in the Nutrient UI.

Requirements

Adding Nutrient to your project

  1. Double-click the project name to access the project file. It will look similar to the image below.

  1. Change the first line from <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.Razor"> and save the project file.

  2. Open your app’s solution, and in the Solution Explorer, right-click on your project and click the Manage NuGet Packages… menu item. This will open the NuGet Package Manager for your solution.

  1. Search for PSPDFKit MAUI, and you’ll find the package on nuget.org.

  2. On the right side, in the panel describing the package, click Install to install the package.

  1. Once the package is installed, click MauiProgram.cs and call the RegisterPSPDFKitSdk() method on the builder. The resulting CreateMauiApp function will look like the following:

public static MauiApp CreateMauiApp()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()
        .RegisterPSPDFKitSdk() // added
        .ConfigureFonts(fonts =>
		{
			fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
			fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
		});

#if DEBUG
    builder.Logging.AddDebug();
#endif
    
    return builder.Build();
	}

Displaying a PDF

  1. In the Resources/Raw folder, create an Assets folder and add a PDF file named demo.pdf.

Note that this is a special folder and it has to be named Assets. PDFs located in this folder can be loaded in the application using a specially designed API, LoadDocumentFromAssetsAsync.

  1. Open MainPage.xaml, remove all the content of ContentPage, and paste the following XML as its content:

<pspdfkit:PDFView x:Name="PDFView" />
  1. You’ll see a green line under pspdfkit:PDFView. If you hover over it, you’ll be given the option for potential fixes. Apply the suggested fix, which will add the following namespace to <ContentPage>:

xmlns:pspdfkit="clr-namespace:PSPDFKit.Sdk;assembly=Sdk"
  1. If you’ve purchased a license and assigned it to a bundle ID, you can add it to the correct platform here:

<pspdfkit:PDFView x:Name="PDFView"
				  License="{OnPlatform 
				  	Android={StaticResource AndroidLicenseKey},
				  	iOS={StaticResource iOSLicenseKey},
				  	MacCatalyst={StaticResource MacCatalystLicenseKey},
				  	WinUI={StaticResource WindowsLicenseKey}}" />

If not, omitting the License property will initialize the PDFView in trial mode.

  1. To subscribe to the Initialized event of PDFView, add the following code to the MainPage.xaml and MainPage.xaml.cs files. In this event handler, use the PDFView.Controller.LoadDocumentFromAssetsAsync function to load the demo.pdf file that was added to the Assets folder:

<pspdfkit:PDFView x:Name="PDFView" Initialized="OnPDFViewInitialized" />
private async void OnPDFViewInitialized(object sender, EventArgs e)
{
	try
	{
		var configuration = PDFView.Controller.CreateViewerConfiguration();
		await PDFView.Controller.LoadDocumentFromAssetsAsync("demo.pdf", configuration);
	}
	catch (Exception ex)
	{
		// Handle exception.
	}
}

Note that you must wait for initialization of the PDFView to be complete before using PdfView.Controller.

  1. In the Build toolbar, choose Debug, and select the platform you’d like to build on — for example, x86 or x64.

  2. Then, in the menu, select Build > Build Solution.

  3. Start the application, and you’ll see demo.pdf loaded in PDFView.

Catalog app

The SDK comes with an example application called the Catalog app. It contains many useful examples for exploring the different features of Nutrient and getting started quickly. The latest Catalog source code can be downloaded here.

Building the Catalog app

To build the Catalog app, ensure you have the required setup for MAUI. If Visual Studio is set, open the solution in Visual Studio, choose the x86 or x64 solution platform, build, and run. Note that based on the platform you want to deploy, you might require Windows or Mac to build.