Getting Started on Xamarin.iOS

Requirements

Creating a new Xamarin Solution

  1. Open Visual Studio and select New Solution in the File > New Solution... menu to create a new solution for your application:

create-new-solution

  1. Choose the Single View App template for your solution:

app-template

  1. When prompted, choose your app name (“PSPDFKit-Demo”) and use the default options:

configure-ios-app

  1. Click on the Next button and select the location to save the solution:

create-app

  1. Click on the Create button to finish.

Install the PSPDFKit SDK via NuGet

  1. Make sure the PSPDFKit-Demo.sln is loaded in Visual Studio.

  2. Right-click on your solution in Visual Studio and select the “Manage NuGet Packages…” menu:

manage-nuget-packages

  1. In the Browse section of nuget.org, search for PSPDFKit.

  2. Select the following two iOS packages: PSPDFKit.iOS.Model and PSPDFKit.iOS.UI:

add-pspdfkit-nuget-packages

  1. Tap on the Add Packages button to add the NuGet packages to your solution.

Displaying a PDF

  1. Add the PDF document you want to display to your application by dragging it into your solution’s resources. On the dialog that’s displayed, select Finish to accept the default integration options. You can use this Quickstart Guide PDF as an example.

drag-and-drop-document

  1. Import PSPDFKit and PSPDFKitUI at the top of your ViewController.cs:

using PSPDFKit.Model;
using PSPDFKit.UI;
  1. Load your PDF document and display the view controller, by implementing ViewDidAppear(Boolean) in the ViewController.cs file like so:

public override void ViewDidAppear(bool animated)
{
	base.ViewDidAppear(animated);

	// 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(rootViewController: pdfViewController);
	_ = this.PresentViewControllerAsync(navController, animated: true);
}

Next Steps

You can find more about Xamarin integration in our GitHub project, and our guides pages.

Requirements

Install the PSPDFKit SDK via NuGet

  1. Open your solution in Visual Studio:

open path/to/YourSolution.sln
  1. Right-click on your solution in Visual Studio and select the “Manage NuGet Packages…” menu:

manage-nuget-packages

  1. In the Browse section of nuget.org, search for PSPDFKit.

  2. Select the following two iOS packages: PSPDFKit.iOS.Model and PSPDFKit.iOS.UI:

add-pspdfkit-nuget-packages

  1. Tap on the Add Packages button to add the NuGet packages to your solution.

Displaying a PDF

  1. Add the PDF document you want to display to your application by dragging it into your solution’s resources. On the dialog that’s displayed, select Finish to accept the default integration options. You can use this Quickstart Guide PDF as an example.

drag-and-drop-document

  1. Import PSPDFKit and PSPDFKitUI at the top of your ViewController.cs:

using PSPDFKit.Model;
using PSPDFKit.UI;
  1. Load your PDF document and display the view controller. This can be done in a button action handler, table view cell selection delegate, or similar:

// 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(rootViewController: pdfViewController);
_ = this.PresentViewControllerAsync(navController, animated: true);
  1. Build and run your application.

Next Steps

You can find more about Xamarin integration in our GitHub project, and our guides pages.

Requirements

Cloning the Catalog Sample Project

  1. Open the Terminal app and change the current working directory. In this case, we’ll use the ~/Downloads directory:

cd ~/Downloads
  1. Clone the PSPDFKit for Xamarin iOS repository:

git clone https://github.com/PSPDFKit/Xamarin-iOS.git
  1. Change the current working directory to the root directory:

cd Xamarin-iOS
  1. Run the following command to download the PSPDFKit dependencies:

./build.sh --target DownloadDeps
  1. Wait a few moments for the dependencies to download.

  2. Open the PSPDFKit solution (PSPDFKit.sln) in Visual Studio:

open PSPDFKit.sln
  1. Build and run the PSPDFCatalog on an iOS Simulator.

catalog-simulator

Next Steps

You can find more about Xamarin integration in our GitHub project, and our guides pages.