Add PDF functionality on iOS
This guide explains how to integrate Nutrient iOS SDK into a new or existing iOS project using UIKit(opens in a new tab). By the end, you’ll be able to display a PDF document using the default Nutrient user interface (UI).
Requirements
- A Mac running macOS
- The latest stable version of Xcode(opens in a new tab)
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:
Open Xcode and select File -> New -> Project.
Under the iOS tab, choose the App template.
Enter your product name (for example, Nutrient-Demo) and organization identifier (for example, com.example). Choose Storyboard as the interface.
Click Next, choose a location to save the project, and click Create.
Adding Nutrient to your project
In Xcode, select your project.
Go to the Package Dependencies tab and click +.
Enter the Nutrient Swift Package URL into the search field:
https://github.com/PSPDFKit/PSPDFKit-SPIn the Dependency Rule fields, select:
- Branch ->
master
— to use the latest version - Version -> Up to Next Minor — for controlled updates
- Branch ->
Click Add Package. Confirm the addition.
In this confirmation step, ensure that the Add to Target column displays the correct target (usually the app target), and that the checkbox on the left is selected. For many projects — especially newly created ones — there will only be one target, so you can click the Add Package button again. However, for more complex projects with multiple targets, it’s important to double-check this setting.
Nutrient will now appear under Swift Package Dependencies.
Displaying a PDF
Add your PDF file to the project by dragging it into the Xcode project navigator. Click Finish when prompted.
In your
UIViewController
subclass, import the Nutrient SDK:import PSPDFKitimport PSPDFKitUI@import PSPDFKit;@import PSPDFKitUI;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)// Update to use your document name.NSURL *documentURL = [NSBundle.mainBundle URLForResource:@"Document" withExtension:@"pdf"];PSPDFDocument *document = [[PSPDFDocument alloc] initWithURL:documentURL];// The configuration object is optional and allows additional customization.PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document configuration:[PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder){builder.pageLabelEnabled = NO;}]];// Present the PDF view controller within a `UINavigationController` to show built-in toolbar buttons.UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pdfController];[self presentViewController:navController animated:YES completion:NULL];Build and run your application.
You should now see your PDF document displayed using Nutrient’s built-in viewer.
Next steps
- Add AI capabilities to Nutrient document viewer
- Customize the UI and other SDK functionality
- Add document collaboration through Instant
- Add OCR support to recognize text in scanned documents
The getting started steps mentioned in this guide are for Swift Package Manager, which is our recommendation. You can also add Nutrient to your project manually or using CocoaPods.