---
title: "SwiftUI PDF library | Nutrient iOS SDK"
canonical_url: "https://www.nutrient.io/guides/ios/getting-started/swiftui/"
md_url: "https://www.nutrient.io/guides/ios/getting-started/swiftui.md"
last_updated: "2026-05-25T09:14:55.616Z"
description: "Learn how to effortlessly use Nutrient iOS SDK in your SwiftUI app with the PDFView struct, simplifying PDF display and configuration for developers."
---

# SwiftUI PDF library

Nutrient iOS SDK exposes specific APIs for native integration with SwiftUI. This eliminates the need for manual [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) wrapping when developing SwiftUI applications, enabling direct utilization of the SDK.

The main entry point is the [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) `struct`, which conforms to SwiftUI’s `View` protocol. [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) wraps [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) into a SwiftUI-compatible container.

## Showing a PDF

To show a PDF, use [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) in the `body` of your SwiftUI view, and pass it a [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document):

```swift

var document: Document

var body: some View {
    PDFView(document: document)
}

```

## Configuration

[`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) has special view modifiers to make configuring it as direct as possible in SwiftUI. The most important properties from [`PDFConfiguration`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfconfiguration) are available. While currently not all available options from [`PDFConfiguration`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfconfiguration) are available as view modifiers for the [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview), the more widely used configuration options are available.

Using these view modifiers in action would look something like this:

```swift

PDFView(document: document).scrollDirection(.vertical).pageTransition(.scrollContinuous).pageMode(.single).spreadFitting(.fill)

```

In case you ever find yourself needing a configuration option that hasn’t yet been mapped to a view modifier, you can always fall back to using a [`PDFConfigurationBuilder`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfconfigurationbuilder) and configuring the SwiftUI [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) in the initializer, like this:

```swift

PDFView(document: document) { builder in
    builder.searchResultZoomScale = 2
}

```

## Controller setup

Since most configuration options, delegates, and actions are exposed in a SwiftUI-friendly way, there are only a few reasons why you should fall back to using the underlying [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) for more advanced setups. You can access the [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) via the [`updateControllerConfiguration(block:)`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview/updatecontrollerconfiguration(block:)) view modifier.

For example, if you want to access properties or methods of [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) that aren’t yet available in SwiftUI, use the following configuration:

```swift

PDFView(document: document).updateControllerConfiguration { pdfController in
        // Use the underlying PDFViewController (pdfController) here.
    }

```

## Delegates

Some of the most relevant delegate methods from [`PDFViewControllerDelegate`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontrollerdelegate) are exposed using view modifiers that take a closure, which are called when a corresponding event happens.

To get a callback whenever a page is displayed, you can use this:

```swift

PDFView(document: document).onWillBeginDisplayingPageView { _, pageIndex in
        print("Displaying page \(pageIndex)")
    }

```

You can find the exposed delegate view modifiers in the [API documentation](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview).

### Actions

Executing actions on the [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) can also be done in SwiftUI. For this, we expose the `actionEventPublisher` subject. You can send various events to this subject to execute all kinds of actions. The action events are of type [`ActionEvent`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview/actionevent):

```swift

@State var actionEventPublisher = PassthroughSubject<PDFView.ActionEvent, Never>()

PDFView(document: document, actionEventPublisher: actionEventPublisher).toolbar {
    Button("Next Page") {
        actionEventPublisher.send(.scrollToNextSpread(animated: true))
    }
}

```

## Bindings

The bindings on [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) can be used to transfer state back and forth between your logic and SwiftUI, with both sides always being automatically up to date.

The available bindings are:

- `pageIndexBinding` — Binds the current [`pageIndex`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/pageindex) of the underlying [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller). It always reflects the current value of the page index. Changing it will set the page index on [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller).

- `viewModeBinding` — Binds the current [`viewMode`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/viewmode) of the underlying [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller). It always reflects the current value of the view mode. Changing it will set the view mode on [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller).

- `selectedAnnotationsBinding` — Binds the current [`selectedAnnotations`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfpageview/selectedannotations) of the visible [`PDFPageView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfpageview) from the underlying [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller). It always reflects the current value of the selected annotations. Changing it will set the selected annotations on the visible page view. Note that all the annotations that will be set in this binding need to be on the same page.

All of these are provided in the [initializer](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview/#Initializers) using the `Binding` property wrapper.

For example, to add a stepper that changes the current page next to a label indicating the current page index, you can use this code snippet:

```swift

@State var pageIndex = PageIndex(0)

VStack {
    Stepper("Current Page: \(pageIndex + 1)",
        value: $pageIndex,
        in: 0...document.pageCount - 1)
    PDFView(document: document, pageIndex: $pageIndex)
}

```

## Navigation bar setup

To make [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) show a navigation bar, you can wrap it in a `NavigationView` or `NavigationStack`, like this:

```swift

NavigationStack {
    PDFView(document: document)
}

```

If you’re integrating [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) in a screen in your app that already has a navigation bar set up using UIKit and you want Nutrient iOS SDK to take it over, make sure [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) is in the view hierarchy of the `UIHostingController` that’s added in a `UINavigationController`, like this:

```swift

struct ContentView: View {
    let document: Document
    var body: some View {
        PDFView(document: document)
    }
}

let hostingController = UIHostingController(rootView: ContentView(document: document))
navigationController.pushViewController(hostingController, animated: true)

```

By default, [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview) won’t add any buttons or set the title of the navigation bar. To learn how to add buttons or set the title, refer to the following sections.

### Toolbar buttons

To add toolbar buttons to your [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview), you can use the SwiftUI `toolbar(_:)` modifier. Nutrient iOS SDK exposes a variety of buttons or a set of buttons that can be used in a toolbar. [`DefaultToolbarButtons`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/defaulttoolbarbuttons) provides a set of default buttons that offer common functionalities for all different view modes. The default buttons may change in future releases of Nutrient iOS SDK.

When setting up toolbar buttons, you must provide a scope using the [`@PDFView.Scope`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview/scope) property wrapper and set it using the [`pdfViewScope(_:)`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview/pdfviewscope(_:)) modifier in the view hierarchy that covers both the toolbar modifier and [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview). Nutrient iOS SDK uses this scope to share state and configuration between the buttons and [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview). This can be done like this:

```swift

@PDFView.Scope var scope

PDFView(document: document).toolbar {
        DefaultToolbarButtons()
    }.pdfViewScope(scope)

```

You can also individually show buttons to fit your application’s specific needs by using views like [`AnnotationButton`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationbutton), [`ThumbnailsButton`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/thumbnailsbutton), or [`ContentEditingButton`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/contenteditingbutton), like this:

```swift

@PDFView.Scope var scope

PDFView(document: document).toolbar {
        ContentEditingButton()
    }.pdfViewScope(scope)

```

### Navigation bar title

To control whether the document title is shown in the navigation bar, use the [`showDocumentTitle(_:)`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview/showdocumenttitle(_:)) modifier. This sets whether the document title should only be shown in the navigation bar, shown in the document label (which floats above document content), or adapt based on the available width, which is the default. You can show the document title like this:

```swift

PDFView(document: document).showDocumentTitle()

```

## Publishers

Additionally, there are some publishers exposed, enabling you to keep track of changes in a SwiftUI-friendly way.

While this API is comfortable to use in SwiftUI, it’s not exclusive to SwiftUI; it can also be used when integrating [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) traditionally via UIKit.

These publishers are built on top of [Apple’s Combine framework](https://developer.apple.com/documentation/combine).

They include [`documentPublisher`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/documentpublisher), [`pageIndexPublisher`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/pageindexpublisher) on [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) and [`savePublisher`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document/savepublisher), and [`annotationChangePublisher`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document/annotationchangepublisher) on [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document).

## Examples

For more details on how to integrate [`PDFView`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfview), look at the SwiftUI examples in the [Catalog example project](https://www.nutrient.io/guides/ios/getting-started/example-projects.md#nutrient-catalog), as they show various use cases when using SwiftUI. You might also want to check out the dedicated `SwiftUIDocumentBrowser` example, which shows how to integrate Nutrient iOS SDK into a document-based SwiftUI app.
---

## Related pages

- [Document Downloads](/guides/ios/miscellaneous/document-downloads.md)
- [Adding Auxiliary Or Decorative Views](/guides/ios/customizing-pdf-pages/adding-auxiliary-or-decorative-views.md)
- [Document Features](/guides/ios/features/document-features.md)
- [Adding Custom Views To A Page](/guides/ios/customizing-pdf-pages/adding-custom-views-to-a-page.md)
- [Options to disable or enable PDF editing on iOS](/guides/ios/features/controlling-pdf-editing.md)
- [Configure document sharing options on iOS](/guides/ios/miscellaneous/document-sharing.md)

