Add PDF functionality on iOS

This guide explains how to integrate Nutrient iOS SDK into a new or existing iOS project. By the end, you’ll be able to display a PDF document using the default Nutrient user interface (UI).

Requirements

Creating your project

Skip this step if you’re using an existing project. Else, if you’re starting a new iOS app, follow the steps mentioned below:

  1. Open Xcode and select File -> New -> Project.

  2. Under the iOS tab, choose the App template.

  3. Enter your product name (for example, Nutrient-Demo) and organization identifier (for example, com.example). Choose Storyboard as the interface.

  4. Click Next, choose a location to save the project, and click Create.

Adding Nutrient to your project

  1. In the terminal, navigate to your project directory:

    cd path/to/YourProject
  2. If you don’t have a Podfile, run:

    pod init
  3. Edit your Podfile and add the following:

    target 'PSPDFKit-Demo' do
    use_frameworks!
    pod 'PSPDFKit', podspec: 'https://my.nutrient.io/pspdfkit-ios/latest.podspec'
    end

    latest.podspec will ensure you always use the latest available version of Nutrient. Alternatively, you can select a specific version by replacing latest.podspec with a version number podspec (for example, 10.2.0.podspec) to update at your own pace. Refer to our guide on advanced CocoaPods integration for version pinning options.

  4. Run:

    pod install
  5. Open the .xcworkspace file Xcode created.

For information on adding Nutrient to your project manually or using Swift Package Manager, refer to the respective guides on manual integration and Swift Package Manager.

Displaying a PDF

  1. Add your PDF file to the project by dragging it into the Xcode project navigator. Click Finish when prompted.

  2. In your UIViewController subclass, import the Nutrient SDK:

    import PSPDFKit
    import PSPDFKitUI
  3. Display the PDF using the following code. You can place this inside viewDidAppear(_:)(opens in a new tab), a button action handler, table view cell selection delegate, or any other suitable place:

    // Update to use your document name.
    let fileURL = Bundle.main.url(forResource: "Document", withExtension: "pdf")!
    let document = Document(url: fileURL)
    // The configuration closure is optional and allows additional customization.
    let pdfController = PDFViewController(document: document) {
    $0.isPageLabelEnabled = false
    }
    // Present the PDF view controller within a `UINavigationController` to show built-in toolbar buttons.
    present(UINavigationController(rootViewController: pdfController), animated: true)
  4. Build and run your application.

You should now see your PDF document displayed using Nutrient’s built-in viewer.

Next steps