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

Requirements

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.

  1. Use the dotnet CLI(opens in a new tab) to create a new iOS solution:

    Terminal window
    dotnet new ios -n Nutrient-Demo

    You can use dotnet new ios -h to learn more about the dotnet new ios command.

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

Terminal window
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

  1. Open your solution in Visual Studio.

    Terminal window
    open path/to/YourSolution.sln
  2. Right-click your solution in Visual Studio and select the Manage NuGet Packages….

    Add nuget package using NuGet manager
  3. In the Browse section of nuget.org, search for Nutrient.dotnet.

  4. Select the Nutrient.dotnet.iOS.UI package.

    Add nuget package using NuGet manager
  5. Tap the Add Packages button to add the NuGet packages to your solution.

Displaying document in your app

  1. Open your solution/csproj in Visual Studio if not already open.

    Terminal window
    open path/to/YourSolution.sln
  2. Add 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.

    Drag and drop document to display
  3. Import PSPDFKit.Model and PSPDFKit.UI at the top of your ViewController.cs file:

    using PSPDFKit.Model;
    using PSPDFKit.UI;
  4. Load your document and display the view controller by implementing FinishedLaunching in the AppDelegate.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 size
    Window = 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 visible
    Window.MakeKeyAndVisible ();
    return true;
    }
  5. 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.