Add PDF functionality on iOS using .NET
This guide explains how to integrate Nutrient .NET for iOS SDK into a new or existing .NET project. By the end, you’ll be able to display a PDF document using the default Nutrient user interface (UI).
View the example repo on GitHub.
View the example repo on GitHub.
Requirements
- Latest stable version of Visual Studio(opens in a new tab)
- Latest stable version of the .NET SDK(opens in a new tab)
- Latest stable version of the
ios
workload(opens in a new tab) - Latest stable version of Xcode(opens in a new tab)
- Latest stable version of the
ios
andmaccatalyst
workloads(opens in a new tab)
Creating a new project
If you already have an existing .NET for iOS or MAUI project that runs on iOS using the latest version of the ios
or maui
workloads, jump to the Adding Nutrient to your project section.
Use the dotnet CLI(opens in a new tab) to create a new iOS solution:
Terminal window dotnet new ios -n Nutrient-DemoYou can use
dotnet new ios -h
to learn more about the dotnet new ios command.Navigate to your newly created .NET
iOS
project directory,Nutrient-Demo
:Terminal window cd ./Nutrient-Demo
Adding Nutrient to your project
Using .NET CLI
Use the dotnet CLI(opens in a new tab) to add the Nutrient NuGet packages to your solution.
dotnet add package Nutrient.dotnet.iOS.UI
You can use dotnet add package -h
to learn more about the dotnet add package command.
Using Visual Studio
Open your solution in Visual Studio.
Terminal window open path/to/YourSolution.slnRight-click your solution in Visual Studio and select the Manage NuGet Packages….
In the Browse section of nuget.org, search for
Nutrient.dotnet
.Select the Nutrient.dotnet.iOS.UI package.
Tap the Add Packages button to add the NuGet packages to your solution.
Displaying document in your app
Open your solution/csproj in Visual Studio if not already open.
Terminal window open path/to/YourSolution.slnAdd the document you want to display to your application by dragging it into your solution’s resources. On the dialog that’s displayed, select OK to accept the default integration options. You can download our sample PDF as an example.
Import
PSPDFKit.Model
andPSPDFKit.UI
at the top of yourViewController.cs
file:using PSPDFKit.Model;using PSPDFKit.UI;Load your document and display the view controller by implementing
FinishedLaunching
in theAppDelegate.cs
file, as demonstrated in the code sample below:public override bool FinishedLaunching(UIApplication app, NSDictionary options){// Create a new window instance based on the screen sizeWindow = new UIWindow (UIScreen.MainScreen.Bounds);// Update to use your document name.var document = new PSPDFDocument (NSUrl.FromFilename ("Document.pdf"));// The configuration object is optional and allows additional customization.var configuration = PSPDFConfiguration.FromConfigurationBuilder ((builder) => {builder.PageMode = PSPDFPageMode.Single;builder.PageTransition = PSPDFPageTransition.ScrollContinuous;builder.ScrollDirection = PSPDFScrollDirection.Vertical;});var pdfViewController = new PSPDFViewController (document, configuration);// Present the PDF view controller within a `UINavigationController` to show built-in toolbar buttons.var navController = new UINavigationController (pdfViewController);Window.RootViewController = navController;// Make the window visibleWindow.MakeKeyAndVisible ();return true;}Build and run your application.
Next steps
Nutrient .NET for iOS SDK exposes the APIs from Nutrient iOS SDK to .NET’s C# language. Refer to our guides, as they contain all the information you need to get started with Nutrient.