---
title: "Aviation example: Displaying flight plan PDF in Swift for iOS"
canonical_url: "https://www.nutrient.io/guides/ios/samples/aviation/"
md_url: "https://www.nutrient.io/guides/ios/samples/aviation.md"
last_updated: "2026-05-30T02:20:01.325Z"
description: "Learn to set up Nutrient for pilots with dark UI and Night Mode. Explore our iOS PDF viewer resources for aviation professionals."
---

# Aviation example: Displaying flight plan PDF in Swift for iOS

Shows how to configure Nutrient to display a flight plan for pilots and a passenger list for the cabin crew. It forces the dark appearance for the UI and renders documents in Night Mode. Get additional resources by visiting our blog on using [iOS PDF viewer in Aviation](/blog/industry-solution-aviation-ios/).

[Get Started](https://www.nutrient.io/sdk/ios/getting-started.md)

[All Samples](https://www.nutrient.io/guides/ios/samples.md)

[Download](https://www.nutrient.io/guides/ios/downloads.md)

[Launch Demo](https://www.nutrient.io/demo/)

---

```swift

//
//  Copyright © 2021-2026 PSPDFKit GmbH. All rights reserved.
//
//  The Nutrient sample applications are licensed with a modified BSD license.
//  Please see License for details. This notice may not be removed from this file.
//

import MapKit
import PSPDFKit
import PSPDFKitUI

/// This example uses the following Nutrient features:
/// - Viewer
/// - Annotations
///
/// See https://www.nutrient.io/sdk/ios for the complete list of Nutrient iOS SDK’s features.

class AviationExample: IndustryExample {

    override init() {
        super.init()

        title = "Aviation"
        contentDescription = "Shows how to configure Nutrient to display a flight plan for pilots and a passenger list for the cabin crew."
        category =.industryExamples
        priority = 6
        extendedDescription = """
        This example shows how to configure the user interface for dark appearance even when the device is using the light appearance.

        This example also shows how to render documents for night mode, which is useful for pilots flying at night.
        """
        url = URL(string: "https://www.nutrient.io/blog/industry-solution-aviation-ios/")!
        image = UIImage(systemName: "airplane.circle")
    }

    override func invoke(with delegate: ExampleRunnerDelegate) -> UIViewController? {
        let flightManualContainerController = FlightManualContainerController(with: self)
        let passengerListContainerController = PassengerListContainerController(with: self)
        let flightManualNavigationController = UINavigationController(rootViewController: flightManualContainerController)
        let passengerListNavigationController = UINavigationController(rootViewController: passengerListContainerController)
        let navigationControllers = [flightManualNavigationController, passengerListNavigationController]

        // Setup the tab bar controller.
        let tabBarController = UITabBarController()
        tabBarController.viewControllers = navigationControllers
        tabBarController.navigationItem.largeTitleDisplayMode =.never
        tabBarController.modalPresentationStyle =.fullScreen

        // Force Dark Mode.
        tabBarController.overrideUserInterfaceStyle =.dark

        // Make the toolbar more opaque over the busy map background.
        // This setting will be automatically matched by the Nutrient annotation toolbar.
        let appearance = UINavigationBarAppearance()
        appearance.backgroundEffect = UIBlurEffect(style:.systemThickMaterialDark)
        navigationControllers.forEach {
            $0.navigationBar.standardAppearance = appearance
            $0.navigationBar.compactAppearance = appearance
        }

        delegate.currentViewController?.present(tabBarController, animated: true)
        return nil
    }
}

/// Custom container view controller subclass for the flight manual.
private class FlightManualContainerController: UIViewController, MKMapViewDelegate {

    var navigationTitleObservation: NSKeyValueObservation?

    init(with example: IndustryExample) {
        super.init(nibName: nil, bundle: nil)
        let flightManualPDFController = FlightManualPDFViewController(with: example)

        // Embed a map view and the PDFViewController in a container view controller.
        let flightManualContainerController = UIViewController()
        title = "Flight Manual"
        flightManualPDFController.view.translatesAutoresizingMaskIntoConstraints = false
        addChild(flightManualPDFController)
        view.addSubview(mapView)
        view.addSubview(flightManualPDFController.view)
        flightManualPDFController.didMove(toParent: flightManualContainerController)

        NSLayoutConstraint.activate([
            view.topAnchor.constraint(equalTo: mapView.topAnchor),
            view.bottomAnchor.constraint(equalTo: flightManualPDFController.view.bottomAnchor),
            flightManualPDFController.view.topAnchor.constraint(equalTo: mapView.bottomAnchor),
            view.leadingAnchor.constraint(equalTo: flightManualPDFController.view.leadingAnchor),
            view.trailingAnchor.constraint(equalTo: flightManualPDFController.view.trailingAnchor),
            mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            mapView.heightAnchor.constraint(equalToConstant: view.frame.height / 3),
        ])

        // The child view controller's navigation item title changes may not propagate automatically to the parent navigation item in all cases.
        navigationTitleObservation = flightManualPDFController.navigationItem.observe(\.title, changeHandler: { [weak self] item, _ in
            self?.navigationItem.title = item.title
        })
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private lazy var mapView: MKMapView = {
        // Embed a map view and the PDFViewController in a container view controller.
        let mapView = MKMapView()
        mapView.delegate = self
        mapView.mapType =.hybridFlyover
        mapView.showsTraffic = false
        mapView.showsScale = true
        mapView.showsCompass = true
        mapView.translatesAutoresizingMaskIntoConstraints = false

        // Set the region of the map view.
        let locationCoordinate = CLLocationCoordinate2D(latitude: 48.12, longitude: 16.5685)
        let region = MKCoordinateRegion(center: locationCoordinate, latitudinalMeters: 3000, longitudinalMeters: 3000)
        mapView.setRegion(region, animated: false)

        // Add a point annotation to the map.
        let mapAnnotation = MKPointAnnotation()
        mapAnnotation.title = "Vienna International Airport"
        mapAnnotation.coordinate = locationCoordinate
        mapView.addAnnotation(mapAnnotation)
        return mapView
    }()

    // MARK: - MKMapViewDelegate

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        guard annotation is MKPointAnnotation else { return nil }

        let identifier = "MapAnnotation"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
        if annotationView == nil {
            annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView?.image = UIImage(namedInCatalog: "airplane")
            annotationView?.canShowCallout = true
        } else {
            annotationView?.annotation = annotation
        }

        return annotationView
    }
}

/// Custom PDF view controller subclass for the flight manual.
private class FlightManualPDFViewController: AviationPDFViewController {

    init(with example: IndustryExample) {
        let document = AssetLoader.writableDocument(for:.flightManual, overrideIfExists: false)
        document.title = "Flight Manual"

        // Customize document sharing.
        // See https://www.nutrient.io/guides/ios/miscellaneous/document-sharing/ for more details.
        let emailConfiguration = DocumentSharingConfiguration.defaultConfiguration(forDestination:.activity).configurationUpdated {
            $0.destination =.email
            $0.fileFormatOptions =.PDF
            $0.annotationOptions = [.embed,.remove]
            $0.pageSelectionOptions = [.all]
        }

        let printConfiguration = DocumentSharingConfiguration.defaultConfiguration(forDestination:.activity).configurationUpdated {
            $0.destination =.print
            $0.fileFormatOptions =.PDF
            $0.annotationOptions = [.flattenForPrint,.remove]
            $0.pageSelectionOptions = [.all]
        }

        let configuration = PDFConfiguration {
            // Customize the annotation toolbar.
            $0.overrideClass(AnnotationToolbar.self, with: AviationAnnotationToolbar.self)

            // Customize the sharing experience.
            if MFMailComposeViewController.canSendMail() {
                $0.sharingConfigurations = [emailConfiguration, printConfiguration]
            } else {
                $0.sharingConfigurations = [printConfiguration]
            }

            // Document view options.
            $0.pageTransition =.scrollPerSpread
            $0.scrollDirection =.horizontal
            $0.pageMode =.single
            $0.spreadFitting =.fit

            // Only allow default and night appearance modes. This will exclude sepia.
            $0.allowedAppearanceModes = [.night]

            // Configure the properties for annotation inspector.
            var annotationProperties = $0.propertiesForAnnotations
            annotationProperties[.ink] = [[.color,.alpha,.lineWidth]] as [[AnnotationStyle.Key]]
            annotationProperties[.square] = [[.color,.alpha,.lineWidth]] as [[AnnotationStyle.Key]]
            annotationProperties[.circle] = [[.color,.alpha,.lineWidth]] as [[AnnotationStyle.Key]]
            annotationProperties[.line] = [[.color,.alpha,.lineWidth]] as [[AnnotationStyle.Key]]
            annotationProperties[.freeText] = [[.fontSize,.fontName,.textAlignment,.color,.fillColor,.calloutAction]] as [[AnnotationStyle.Key]]

            $0.propertiesForAnnotations = annotationProperties

            // Miscellaneous configuration options.
            $0.thumbnailBarMode =.scrubberBar
            $0.searchMode =.modal
            $0.useParentNavigationBar = true
            $0.userInterfaceViewMode =.always

            // When `.top` is a supported toolbar position, the document label must be disabled.
            $0.documentLabelEnabled =.NO

            // We handle the navigation bar title manually.
            $0.allowToolbarTitleChange = false
        }

        super.init(document: document, configuration: configuration)

        // Customize the toolbar.
        // See https://www.nutrient.io/guides/ios/customizing-the-interface/customizing-the-toolbar/ for more details.
        moreInfo = MoreInfoCoordinator(with: example, presentationContext: self)
        navigationItem.leftBarButtonItems = [closeButtonItem, moreInfo.barButton, brightnessButtonItem]

        // Force the night appearance mode.
        // See https://www.nutrient.io/guides/ios/customizing-the-interface/appearance-mode-manager/ for more details.
        appearanceModeManager.appearanceMode =.night

        // Do not reset the appearance mode when the view disappears.
        shouldResetAppearanceModeWhenViewDisappears = false

        // Only support the top in the main toolbar position for the annotation toolbar.
        annotationToolbarController?.annotationToolbar.supportedToolbarPositions =.inTopBar
        annotationToolbarController?.annotationToolbar.toolbarPosition =.inTopBar

        // Only show the outlines and bookmarks in the document info.
        // See https://www.nutrient.io/guides/ios/customizing-the-interface/customizing-the-available-document-information/ for more details.
        documentInfoCoordinator.availableControllerOptions = [.outline,.bookmarks]

        // Do not show the filter options segmented control when viewing the thumbnails.
        thumbnailController.filterOptions = nil

        setUpdateSettingsForBoundsChange { [weak self] _ in
            self?.updateNavigationBar()
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: View Lifecycle

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        updateNavigationBar()
    }

    // MARK: Customization

    private func updateNavigationBar() {
        let availableWidth = view.bounds.inset(by: view.safeAreaInsets).width

        // Show more items on wide screens. 440 is the minimum width needed to show 7 items including the close button.
        // Hide the title in the navigation bar if space is constrained and enable the floating document label in the document.
        if availableWidth > 440 {
            navigationItem.rightBarButtonItems = [activityButtonItem, searchButtonItem, annotationButtonItem, outlineButtonItem]
            updateConfiguration {
                $0.documentLabelEnabled =.NO
            }
            navigationItem.title = document?.title
        } else {
            navigationItem.rightBarButtonItems = [activityButtonItem, annotationButtonItem, outlineButtonItem]
            updateConfiguration {
                $0.documentLabelEnabled =.YES
            }
            navigationItem.title = nil
        }
    }
}

/// Custom container view controller subclass for the passenger list.
private class PassengerListContainerController: UIViewController {

    var navigationTitleObservation: NSKeyValueObservation?

    init(with example: IndustryExample) {
        super.init(nibName: nil, bundle: nil)
        // Create the passenger list PDF view controller.
        let passengerListPDFController = PassengerListPDFViewController(with: example)

        // Embed the PDFViewController in a container view controller.
        title = "Passenger List"
        addChild(passengerListPDFController)
        view.addSubview(passengerListPDFController.view)
        passengerListPDFController.didMove(toParent: self)

        // The child view controller's navigation item title changes may not propagate automatically to the parent navigation item in all cases.
        navigationTitleObservation = passengerListPDFController.navigationItem.observe(\.title, changeHandler: { [weak self] item, _ in
            self?.navigationItem.title = item.title
        })
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

/// Custom PDF view controller subclass for the passenger list.
private class PassengerListPDFViewController: AviationPDFViewController {

    init(with example: IndustryExample) {
        let document = AssetLoader.writableDocument(for:.passengerList, overrideIfExists: false)
        document.title = "Passenger List"

        let configuration = PDFConfiguration {
            // Customize the annotation toolbar.
            $0.overrideClass(AnnotationToolbar.self, with: AviationAnnotationToolbar.self)

            // Document view options.
            $0.pageTransition =.scrollContinuous
            $0.scrollDirection =.vertical
            $0.pageMode =.single
            $0.spreadFitting =.fill

            // Only allow default and night appearance modes. This will exclude sepia.
            $0.allowedAppearanceModes = [.night]

            // Miscellaneous configuration options.
            $0.thumbnailBarMode =.scrubberBar
            $0.searchMode =.inline
            $0.useParentNavigationBar = true
            $0.userInterfaceViewMode =.always

            // When `.top` is a supported toolbar position, the document label must be disabled.
            $0.documentLabelEnabled =.NO

            // We handle the navigation bar title manually.
            $0.allowToolbarTitleChange = false
        }

        super.init(document: document, configuration: configuration)

        // Do not reset the appearance mode when the view disappears.
        shouldResetAppearanceModeWhenViewDisappears = false

        // Customize the toolbar.
        // See https://www.nutrient.io/guides/ios/customizing-the-interface/customizing-the-toolbar/ for more details.
        moreInfo = MoreInfoCoordinator(with: example, presentationContext: self)
        navigationItem.leftBarButtonItems = [closeButtonItem, moreInfo.barButton, brightnessButtonItem]

        // Only support the top in the main toolbar position for the annotation toolbar.
        annotationToolbarController?.annotationToolbar.supportedToolbarPositions =.inTopBar
        annotationToolbarController?.annotationToolbar.toolbarPosition =.inTopBar

        setUpdateSettingsForBoundsChange { [weak self] _ in
            self?.updateNavigationBar()
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: View Lifecycle

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        updateNavigationBar()
    }

    // MARK: Customization

    private func updateNavigationBar() {
        let availableWidth = view.bounds.inset(by: view.safeAreaInsets).width

        // Show more items on wide screens. 440 is the minimum width needed to show 7 items including the close button.
        // Hide the title in the navigation bar if space is constrained and enable the floating document label in the document.
        if availableWidth > 440 {
            navigationItem.rightBarButtonItems = [activityButtonItem, searchButtonItem, annotationButtonItem, toggleAnnotationVisibilityBarButtonItem]
            updateConfiguration {
                $0.documentLabelEnabled =.NO
            }
            navigationItem.title = document?.title
        } else {
            navigationItem.rightBarButtonItems = [activityButtonItem, annotationButtonItem, toggleAnnotationVisibilityBarButtonItem]
            updateConfiguration {
                $0.documentLabelEnabled =.YES
            }
            navigationItem.title = nil
        }
    }
}

/// Custom PDF view controller class.
private class AviationPDFViewController: PDFViewController, PDFViewControllerDelegate {

    /// Used for showing the more info alert.
    var moreInfo: MoreInfoCoordinator!

    override func commonInit(with document: Document?, configuration: PDFConfiguration) {
        super.commonInit(with: document, configuration: configuration.configurationUpdated { builder in
            // Disable creating the following annotation types.
            let disabledMenuItems = [
                Annotation.ToolVariantID(tool:.signature),
                Annotation.ToolVariantID(tool:.ink, variant:.inkHighlighter),
                Annotation.ToolVariantID(tool:.image),
                Annotation.ToolVariantID(tool:.stamp),
                Annotation.ToolVariantID(tool:.sound),
                Annotation.ToolVariantID(tool:.eraser)
            ]
            builder.createAnnotationMenuGroups = builder.createAnnotationMenuGroups.map { group in.init(items: group.items.filter { item in!disabledMenuItems.contains {
                        $0.tool == item.type && $0.variant == item.variant

                    }
                })
            }
        })

        delegate = self

        // Customize the default stamps.
        // See https://www.nutrient.io/guides/ios/annotations/stamp-annotations-configuration/ for more details.
        var defaultStamps = [StampAnnotation]()
        let approvedStamp = StampAnnotation(title: "Approved")
        approvedStamp.boundingBox = CGRect(x: 0, y: 0, width: 200, height: 70)
        approvedStamp.color = UIColor.green
        defaultStamps.append(approvedStamp)
        let rejectedStamp = StampAnnotation(title: "Rejected")
        rejectedStamp.boundingBox = CGRect(x: 0, y: 0, width: 200, height: 70)
        rejectedStamp.color = UIColor.red
        defaultStamps.append(rejectedStamp)

        StampViewController.defaultStampAnnotations = defaultStamps

        // Disable text interaction.
        interactions.allTextInteractions.isEnabled = false
    }

    // Cleanup to avoid affecting other examples.
    deinit {
        // Reset the default stamps so other examples will use the default stamps.
        StampViewController.defaultStampAnnotations = nil
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        moreInfo.showAlertIfNeeded()
    }

    lazy var toggleAnnotationVisibilityBarButtonItem: UIBarButtonItem = {
        let toggleAnnotationVisibility = UIBarButtonItem(image: UIImage(namedInCatalog: "hide"), style:.plain, target: self, action: #selector(didTapToggleAnnotationVisibilityBarButtonItem))

        toggleAnnotationVisibility.title = "hide"
        return toggleAnnotationVisibility
    }()

    // MARK: Private

    private lazy var mapView: UIView? = {
        return parent?.view.subviews.first(where: { $0.isKind(of: MKMapView.self) })
    }()

    @objc private func didTapToggleAnnotationVisibilityBarButtonItem(_ sender: UIBarButtonItem) {
        // Let link annotations be always visible.
        if sender.title == "hide" {
            setVisibleAnnotationTypes(.link)
            sender.title = "show"
            sender.image = UIImage(namedInCatalog: "show")
        } else {
            setVisibleAnnotationTypes(.all)
            sender.title = "hide"
            sender.image = UIImage(namedInCatalog: "hide")
        }
    }

    private func setVisibleAnnotationTypes(_ types: Annotation.Kind) {
        // Update the render types.
        document?.renderAnnotationTypes = types
        // Clear the cache so that pages are re-rendered once updated.
        PSPDFKit.SDK.shared.cache.remove(for: document)
        for pageView in visiblePageViews {
            pageView.updateAnnotationViews(animated: false)
            pageView.update()
        }
    }

    // MARK: FlexibleToolbarContainerDelegate

    override func flexibleToolbarContainerWillShow(_ container: FlexibleToolbarContainer) {
        // Disable user interaction and dim the map view when annotation toolbar becomes visible.
        if let mapView {
            mapView.isUserInteractionEnabled = false
            mapView.mask = UIView(frame: mapView.frame)
            mapView.mask?.backgroundColor =.black
            mapView.mask?.alpha = 0.5
        }

        // If the annotations visibility is disabled, we enable the visibility when annotation toolbar becomes visible.
        if toggleAnnotationVisibilityBarButtonItem.title == "show" {
            didTapToggleAnnotationVisibilityBarButtonItem(toggleAnnotationVisibilityBarButtonItem)
        }
    }

    override func flexibleToolbarContainerWillHide(_ container: FlexibleToolbarContainer) {
        // Restore the map view's state when annotation toolbar will hide.
        if let mapView {
            mapView.isUserInteractionEnabled = true
            mapView.mask = nil
        }
    }

    // MARK: - PDFViewControllerDelegate

    func pdfViewController(_ pdfController: PDFViewController, shouldShow controller: UIViewController, options: [String: Any]? = nil, animated: Bool) -> Bool {
        // Customize the stamp view controller.
        let stampController = PSPDFChildViewControllerForClass(controller, StampViewController.self) as? StampViewController
        stampController?.customStampEnabled = false
        stampController?.dateStampsEnabled = false

        // Force Dark Mode for presented controllers.
        let presentationRoot = controller.navigationController?? controller
        presentationRoot.overrideUserInterfaceStyle =.dark

        return true
    }

    func pdfViewController(_ sender: PDFViewController, menuForCreatingAnnotationAt point: CGPoint, onPageView pageView: PDFPageView, appearance: EditMenuAppearance, suggestedMenu: UIMenu) -> UIMenu {
        let invertColorsAction = UIAction(title: "Invert Colors") { _ in
            if self.appearanceModeManager.appearanceMode ==.night {
                self.appearanceModeManager.appearanceMode = []
            } else {
                self.appearanceModeManager.appearanceMode =.night
            }
        }
        return suggestedMenu.prepend([invertColorsAction])
    }
}

/// Custom annotation toolbar class to allow the annotation toolbar customization.
/// See https://www.nutrient.io/guides/ios/customizing-the-interface/customizing-the-annotation-toolbar/ for more details.
private class AviationAnnotationToolbar: AnnotationToolbar {

    private var clearAnnotationsButton: ToolbarButton = ToolbarButton()

    override init(annotationStateManager: AnnotationStateManager) {
        super.init(annotationStateManager: annotationStateManager)

        NotificationCenter.default.addObserver(self, selector: #selector(updateClearAnnotationButton), name:.PSPDFAnnotationChanged, object: nil)

        NotificationCenter.default.addObserver(self, selector: #selector(updateClearAnnotationButton), name:.PSPDFAnnotationsAdded, object: nil)

        NotificationCenter.default.addObserver(self, selector: #selector(updateClearAnnotationButton), name:.PSPDFAnnotationsRemoved, object: nil)

        NotificationCenter.default.addObserver(self, selector: #selector(updateClearAnnotationButton), name:.PSPDFDocumentViewControllerWillBeginDisplayingSpreadView, object: nil)

        // Customize the annotation toolbar buttons.
        // See https://www.nutrient.io/guides/ios/customizing-the-interface/customizing-the-annotation-toolbar/#annotation-buttons for more details.

        typealias Item = AnnotationToolConfiguration.ToolItem
        typealias Group = AnnotationToolConfiguration.ToolGroup
        let ink = Item(type:.ink)
        let square = Item(type:.square)
        let circle = Item(type:.circle)
        let line = Item(type:.line)
        let freeText = Item(type:.freeText)
        let note = Item(type:.note)
        let stamp = Item(type:.stamp)
        let selectionTool = Item(type:.selectionTool)

        let compactGroups = [
            Group(items: [ink]),
            Group(items: [square, circle, line]),
            Group(items: [freeText, note]),
            Group(items: [stamp]),
            Group(items: [selectionTool])
        ]

        let compactConfiguration = AnnotationToolConfiguration(annotationGroups: compactGroups)

        let regularGroups = [
            Group(items: [ink]),
            Group(items: [square]),
            Group(items: [circle]),
            Group(items: [line]),
            Group(items: [freeText]),
            Group(items: [note]),
            Group(items: [stamp]),
            Group(items: [selectionTool])
        ]

        let regularConfiguration = AnnotationToolConfiguration(annotationGroups: regularGroups)

        configurations = [compactConfiguration, regularConfiguration]

        let clearImage = SDK.imageNamed("trash")?.withRenderingMode(.alwaysTemplate)
        clearAnnotationsButton.accessibilityLabel = "Clear"
        clearAnnotationsButton.image = clearImage
        clearAnnotationsButton.addTarget(self, action: #selector(clearButtonPressed(_:)), for:.touchUpInside)

        self.additionalButtons = [clearAnnotationsButton]
        updateClearAnnotationButton()
    }

    // MARK: Clear Button Action

    @objc func clearButtonPressed(_ sender: ToolbarButton) {
        let pdfController = annotationStateManager.pdfController
        let document = pdfController?.document
        let allTypesButLinkAndForms = Annotation.Kind.all.subtracting([.link,.widget])
        guard let annotations = document?.allAnnotations(of: allTypesButLinkAndForms).flatMap({ $0.value }) else {
            return
        }

        document?.remove(annotations: annotations, options: nil)
        SDK.shared.cache.remove(for: document)
        pdfController?.reloadData()
    }

    // MARK: PDFAnnotationStateManagerDelegate

    override func annotationStateManager(_ manager: AnnotationStateManager, didChangeUndoState undoEnabled: Bool, redoState redoEnabled: Bool) {
        super.annotationStateManager(manager, didChangeUndoState: undoEnabled, redoState: redoEnabled)
        updateClearAnnotationButton()
    }

    // MARK: Private

    @objc private func updateClearAnnotationButton() {
        let pdfController = annotationStateManager.pdfController
        let document = pdfController?.document
        let allTypesButLinkAndForms = Annotation.Kind.all.subtracting([.link,.widget])
        guard let annotations = document?.allAnnotations(of: allTypesButLinkAndForms) else { return }
        // Enable the button only if there are annotations found to clear.
        clearAnnotationsButton.isEnabled = annotations.isEmpty == false
    }
}

```

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.

---

## Related pages

- [Customize PDF page lables in Swift for iOS](/guides/ios/samples/custom-page-label.md)
- [Add file annotation to PDF in Swift for iOS](/guides/ios/samples/add-file-annotation-with-embedded-file.md)
- [Add a custom cloudy rectangle annotation to a PDF in Swift for iOS](/guides/ios/samples/add-custom-cloudy-rectangle.md)
- [Add an image signature to PDF in Swift for iOS](/guides/ios/samples/add-image-signature-to-pdf-programmatically.md)
- [Add an Apple Maps widget to a PDF page in Swift for iOS](/guides/ios/samples/add-map-widget-to-pdf.md)
- [Add video annotation to PDF in Swift for iOS](/guides/ios/samples/add-video-annotation-to-pdf.md)
- [Image annotations in Swift for iOS](/guides/ios/samples/annotate-images.md)
- [Add image gallery to PDF in Swift for iOS](/guides/ios/samples/add-image-gallery-to-pdf.md)
- [Add annotation buttons to PDF toolbar in Swift for iOS](/guides/ios/samples/annotation-buttons-in-navigation-bar.md)
- [Customize blend modes in stamp annotations in Swift for iOS](/guides/ios/samples/annotation-inspector-stamp-blend-mode.md)
- [Add analytics to PDF components in Swift for iOS](/guides/ios/samples/analytics.md)
- [Create an always-dark annotation toolbar in Swift for iOS](/guides/ios/samples/always-dark-annotation-toolbar.md)
- [Creating effective link annotations on iOS](/guides/ios/samples/annotations.md)
- [Maintain annotation aspect ratio in Swift](/guides/ios/samples/aspect-ratio-conserving-resizing.md)
- [Create a custom appearance stream generator in Swift for iOS](/guides/ios/samples/appearance-stream-generator.md)
- [Write PDF annotations to XFDF in Swift for iOS](/guides/ios/samples/annotations-to-xfdf.md)
- [Add copyright watermark to PDF in Swift for iOS](/guides/ios/samples/add-copyright-watermark-to-pdf.md)
- [Add text annotation to PDF in Swift for iOS](/guides/ios/samples/add-text-annotation-to-pdf.md)
- [Embed, flatten, or remove PDF annotations in Swift for iOS](/guides/ios/samples/annotation-processing.md)
- [Add calculator to PDF using JavaScript on iOS](/guides/ios/samples/calculator.md)
- [Enable auto-save in PDF using Swift for iOS](/guides/ios/samples/auto-saving-pdf.md)
- [Blur PDF page in Swift for iOS](/guides/ios/samples/blur-pdf-pages.md)
- [Programatically create PDF annotations in Swift for iOS](/guides/ios/samples/add-annotations-to-pdf-programmatically.md)
- [Using a custom annotation provider in Swift for iOS](/guides/ios/samples/annotation-provider-with-rotation.md)
- [Asynchronously sign PDF in Swift for iOS](/guides/ios/samples/asynchronous-digital-signature-in-pdf.md)
- [Embed PDFViewController as a child in iOS](/guides/ios/samples/child-view-controller.md)
- [PDFViewController controller state in Swift for iOS](/guides/ios/samples/controller-state.md)
- [Collaborating on PDFs in board meetings using Swift for iOS](/guides/ios/samples/board-meeting.md)
- [Create link annotations in PDF using Swift for iOS](/guides/ios/samples/create-link-annotation-in-pdf.md)
- [Embed Nutrient as a child view controller in Swift for iOS](/guides/ios/samples/child-view-controller-using-parent-navigation-bar.md)
- [Present a confirmation sheet for iOS annotations](/guides/ios/samples/confirm-annotation-deletion.md)
- [Prepare PDF to capture digital signature in Swift for iOS](/guides/ios/samples/contained-digital-signatures.md)
- [Prepare PDF to embed PAdES digital signature in Swift for iOS](/guides/ios/samples/contained-pades-digital-signature.md)
- [Create PDF bookmark with UI in Swift for iOS](/guides/ios/samples/create-pdf-bookmark-name-ui.md)
- [Add a custom free text input accessory in Swift for iOS](/guides/ios/samples/custom-free-text-input-accessory.md)
- [Custom annotation provider in Swift for iOS](/guides/ios/samples/custom-annotation-provider.md)
- [Create password-protected PDF in Swift for iOS](/guides/ios/samples/create-password-protected-pdf.md)
- [Continiously create free text annotations in Swift for iOS](/guides/ios/samples/create-free-text-annotations-continuously.md)
- [Clear all PDF annotations with a button in Swift for iOS](/guides/ios/samples/custom-button-in-annotation-toolbar.md)
- [Select PDF text and create a note in Swift for iOS](/guides/ios/samples/create-note-from-selection.md)
- [Customize annotation link border color in Swift for iOS](/guides/ios/samples/custom-link-border-color.md)
- [Create PDF programmatically in Swift for iOS](/guides/ios/samples/create-pdf-programmatically.md)
- [Add custom font sizes to free text keyboard in Swift for iOS](/guides/ios/samples/custom-buttons-free-text-keyboard-toolbar.md)
- [Custom PDF bookmark provider in Swift for iOS](/guides/ios/samples/custom-pdf-bookmark-provider.md)
- [Custom Comments Ui](/guides/ios/samples/custom-comments-ui.md)
- [Use a custom image picker controller in Swift for iOS](/guides/ios/samples/custom-image-picker-controller.md)
- [Customize PDF outline in Swift for iOS](/guides/ios/samples/custom-pdf-outline-controller.md)
- [Display building floor plans in iOS with Swift](/guides/ios/samples/construction.md)
- [Customize PDF sharing options in Swift for iOS](/guides/ios/samples/custom-pdf-sharing-options.md)
- [Custom Thumbnail Page Label](/guides/ios/samples/custom-thumbnail-page-label.md)
- [Customize pencil interactions on PDF using Swift for iOS](/guides/ios/samples/custom-pencil-interaction-action.md)
- [Custom thumbnail PDF view filter in Swift for iOS](/guides/ios/samples/custom-thumbnail-view-controller-filter.md)
- [Customize the search result cell in Swift for iOS](/guides/ios/samples/custom-search-result-cell.md)
- [Customize PDF tab titles in Swift for iOS](/guides/ios/samples/custom-tabbed-bar-title.md)
- [Customize PDF annotation toolbar in Swift for iOS](/guides/ios/samples/customize-pdf-annotation-toolbar.md)
- [Custom PDF stamp annotation in Swift for iOS](/guides/ios/samples/custom-pdf-stamp-annotations.md)
- [Customize the filename of shared PDF in Swift for iOS](/guides/ios/samples/custom-sharing-filenames.md)
- [Customized note annotation view controller in Swift for iOS](/guides/ios/samples/customized-note-annotation-view-controller.md)
- [How to disable digital signature removal in PDFs](/guides/ios/samples/disable-removing-digital-signature.md)
- [Disable PDF annotation editing in Swift for iOS](/guides/ios/samples/disable-annotation-editing.md)
- [Disable annotations reviews in PDF using Swift for iOS](/guides/ios/samples/disable-annotation-reviews.md)
- [Display PDF in inbox directory using Swift for iOS](/guides/ios/samples/display-pdf-inbox.md)
- [Initialize a PDF with data in Swift for iOS](/guides/ios/samples/document-data-provider-pdf-from-data.md)
- [Disable bookmark editing in PDF using Swift for iOS](/guides/ios/samples/disable-bookmark-editing.md)
- [Add watermark to all PDF pages using Swift for iOS](/guides/ios/samples/draw-watermark-on-pdf-pages.md)
- [Encrypt and decrypt a PDF using Swift for iOS](/guides/ios/samples/encrypt-decrypt-pdf.md)
- [Customize the PDF search highlight color in Swift for iOS](/guides/ios/samples/custom-search-highlight-color.md)
- [Save reading position in PDF using Swift for iOS](/guides/ios/samples/document-view-state-restoration.md)
- [Disable scroll bouncing in PDF using Swift for iOS](/guides/ios/samples/disable-scroll-bouncing.md)
- [Implement a Document Picker sidebar in Swift for iOS](/guides/ios/samples/document-picker-sidebar.md)
- [Document With Original Url Set](/guides/ios/samples/document-with-original-url-set.md)
- [Encrypt disk cache when rendering PDF in Swift for iOS](/guides/ios/samples/encrypted-cache.md)
- [PDF highlight annotation blend mode menu in Swift for iOS](/guides/ios/samples/highlight-annotation-blend-mode-menu.md)
- [Fixed-sized PDF stamp annotations in Swift for iOS](/guides/ios/samples/floating-pdf-stamp-annotation.md)
- [Exit PDF drawing mode automatically in Swift for iOS](/guides/ios/samples/exit-drawing-mode-automatically.md)
- [Apply XFDF annotations and save it as new PDF in Swift for iOS](/guides/ios/samples/embedded-xfdf-annotation-provider.md)
- [Allow freeform image annotation resizing in Swift for iOS](/guides/ios/samples/freeform-image-resize.md)
- [Disable bookmark renaming in PDF using Swift for iOS](/guides/ios/samples/disable-bookmark-renaming.md)
- [Convert HTML to PDF using Swift for iOS](/guides/ios/samples/html-to-pdf.md)
- [Add video, audio, image annotation to PDF in Swift for iOS](/guides/ios/samples/gallery.md)
- [Add a bottom inset to the user interface in Swift for iOS](/guides/ios/samples/inset-user-interface.md)
- [Insert page into PDF from another document in Swift for iOS](/guides/ios/samples/insert-pdf-page-from-document.md)
- [Customize comment font size in PDF using Swift for iOS](/guides/ios/samples/large-font-for-comments.md)
- [Monitor UI touches using Swift for iOS](/guides/ios/samples/monitor-touches.md)
- [Customize PDF form appearance in Swift for iOS](/guides/ios/samples/customizing-pdf-form-appearance.md)
- [Customize the annotation selection knobs in Swift for iOS](/guides/ios/samples/custom-selection-knobs.md)
- [Customize vertical annotation toolbar in Swift for iOS](/guides/ios/samples/custom-vertical-annotation-toolbar.md)
- [Customize the annotations list in Swift for iOS](/guides/ios/samples/customizing-annotation-list.md)
- [Encrypted Xfdf Annotation Provider](/guides/ios/samples/encrypted-xfdf-annotation-provider.md)
- [Face redaction in document using Swift for iOS](/guides/ios/samples/face-redaction-in-pdf.md)
- [Draw all PDF annotations as overlays in Swift for iOS](/guides/ios/samples/draw-annotations-as-overlay.md)
- [Configuring PDF reader in Swift for iOS](/guides/ios/samples/e-reader.md)
- [Customize PDF view margins using Swift for iOS](/guides/ios/samples/dynamic-margins.md)
- [Lazy load PDF annotations in Swift for iOS](/guides/ios/samples/lazy-load-pdf-annotations.md)
- [Highlight text in PDF using Swift for iOS](/guides/ios/samples/highlight-text-in-pdf.md)
- [LMS example: Take and grade an exam using Swift for iOS](/guides/ios/samples/e-learning.md)
- [Using Instant JSON to collaborate on PDFs in Swift for iOS](/guides/ios/samples/instant-json.md)
- [Generate a PDF report using Swift for iOS](/guides/ios/samples/generate-pdf-report.md)
- [Hide or reveal an area in a PDF using Swift for iOS](/guides/ios/samples/hide-reveal-area-in-pdf.md)
- [Configuring multiline titles in PDF using Swift for iOS](/guides/ios/samples/multiline-pdf-title.md)
- [Link annotation view customization in Swift for iOS](/guides/ios/samples/link-annotation-view-customization.md)
- [OCR PDF using Swift for iOS](/guides/ios/samples/ocr-pdf.md)
- [Add overlay views to PDF in Swift for iOS](/guides/ios/samples/overlay-views.md)
- [Custom PDF page labels in the sharing UI in Swift for iOS](/guides/ios/samples/page-labels-in-sharing-ui.md)
- [Open AES-encrypted PDF in Swift for iOS](/guides/ios/samples/open-aes-encrypted-pdf.md)
- [Password Not Preset](/guides/ios/samples/password-not-preset.md)
- [Custom saving options after editing PDF in Swift for iOS](/guides/ios/samples/pdf-editor-custom-saving-confirmation.md)
- [Customize PDF editor toolbar using Swift for iOS](/guides/ios/samples/pdf-editor-toolbar-customization.md)
- [Toggle PDF form field highlight color in Swift for iOS](/guides/ios/samples/pdf-form-highlight-color.md)
- [Render drawings on PDF pages using Swift for iOS](/guides/ios/samples/pdf-page-drawing.md)
- [Custom page template in PDF editor using Swift for iOS](/guides/ios/samples/pdf-editor-custom-templates.md)
- [PDF reflow with Reader View in Swift for iOS](/guides/ios/samples/pdf-reader-view.md)
- [Create email snippet when sharing PDF in Swift for iOS](/guides/ios/samples/predefined-email-body.md)
- [Create PDF teleprompter using Swift for iOS](/guides/ios/samples/pdf-teleprompter.md)
- [Printer defaults for PDF annotations in Swift for iOS](/guides/ios/samples/printer-defaults.md)
- [Redact text in PDF using Swift for iOS](/guides/ios/samples/pdf-redaction.md)
- [Persist view settings using Swift for iOS](/guides/ios/samples/persist-view-settings.md)
- [Display PDFViewController in popover using Swift for iOS](/guides/ios/samples/popover-presentation.md)
- [Open PDF with preset password using Swift for iOS](/guides/ios/samples/preset-pdf-passwords.md)
- [Customize PDF view settings in Swift for iOS](/guides/ios/samples/pdf-view-settings.md)
- [Getting started with iOS playground](/guides/ios/samples/playground.md)
- [Programmatically edit PDFs using Swift for iOS](/guides/ios/samples/programmatic-pdf-editing.md)
- [Customize iOS annotation inspector color presets](/guides/ios/samples/preset-customization.md)
- [Download PDF from URL using Swift for iOS](/guides/ios/samples/remote-document-url.md)
- [Programmatically go to PDF outline in Swift for iOS](/guides/ios/samples/programmatically-go-to-outline.md)
- [Remove password from PDF using Swift for iOS](/guides/ios/samples/remove-pdf-password.md)
- [Rotate PDF page using Swift for iOS](/guides/ios/samples/rotate-pdf-page.md)
- [Rotate PDF pages with Swift](/guides/ios/samples/rotate-page-temporarily.md)
- [Configure PDF annotation toolbar using Swift for iOS](/guides/ios/samples/manual-toolbar-setup.md)
- [Cycle through PDF documents using Swift for iOS](/guides/ios/samples/page-view-controller.md)
- [PDF collaboration using Swift for iOS](/guides/ios/samples/pdf-collaboration.md)
- [Show PDF download progress in Swift for iOS](/guides/ios/samples/pdf-download-progress.md)
- [Compare PDF documents using Swift for iOS](/guides/ios/samples/pdf-document-comparison.md)
- [PDF magazine reader using Swift for iOS](/guides/ios/samples/pdf-magazine-reader.md)
- [PDF text redaction using regex in Swift for iOS](/guides/ios/samples/redact-pdf-text-using-regex.md)
- [PDF page scale and resize using Swift for iOS](/guides/ios/samples/pdf-page-scaling.md)
- [Auto-save PDF annotation changes in Swift for iOS](/guides/ios/samples/save-as-pdf.md)
- [Customize scrubber bar with buttons using Swift for iOS](/guides/ios/samples/scrubber-bar-with-buttons.md)
- [Programtically search a PDF using Swift for iOS](/guides/ios/samples/search-without-controller.md)
- [Enable saving confirmation when exiting PDF in Swift for iOS](/guides/ios/samples/save-confirmation.md)
- [Customize view controller for screen mirroring in Swift for iOS](/guides/ios/samples/screen-mirroring.md)
- [Search multiple PDF files using Swift for iOS](/guides/ios/samples/search-multiple-pdf-files.md)
- [Select all text in a PDF using Swift for iOS](/guides/ios/samples/select-all-pdf-text.md)
- [Select free text annotation in PDF using Swift for iOS](/guides/ios/samples/select-free-text-annotations.md)
- [Show multiple files as a single PDF using Swift for iOS](/guides/ios/samples/show-multiple-files-in-pdf.md)
- [Show note controller for highlights in Swift for iOS](/guides/ios/samples/show-note-controller-for-highlights.md)
- [Simplifying the font picker for text annotation using Swift for iOS](/guides/ios/samples/simple-font-picker.md)
- [Simplifying the annotation inspector using Swift for iOS](/guides/ios/samples/simple-annotation-inspector.md)
- [Convert stamp into a PDF button in Swift for iOS](/guides/ios/samples/stamp-button.md)
- [Create a custom PDF navigation bar with SwiftUI for iOS](/guides/ios/samples/swiftui-custom-navigation-bar.md)
- [Embed a SwiftUI view inside a page view on iOS](/guides/ios/samples/swiftui-on-page-view.md)
- [SwiftUI split screen: Display two PDF views side by side on iOS](/guides/ios/samples/swiftui-split-screen.md)
- [Enable fixed PDF toolbar position in Swift for iOS](/guides/ios/samples/top-toolbar-position.md)
- [Swiftui Sharing](/guides/ios/samples/swiftui-sharing.md)
- [Use PDFViewController with SwiftUI for iOS](/guides/ios/samples/swiftui.md)
- [Update configuration when rotating PDF in Swift for iOS](/guides/ios/samples/update-configuration-when-rotating.md)
- [Show or hide PDF annotations using Swift for iOS](/guides/ios/samples/toggle-annotation-visibility.md)
- [Multi-user PDF collaboration using Swift for iOS](/guides/ios/samples/multi-user-pdf-collaboration.md)
- [Convert MS Office (DOCX, XLSX, PPTX) to PDF in Swift for iOS](/guides/ios/samples/office-to-pdf-conversion.md)
- [Display measurements on PDF pages or spreads in Swift for iOS](/guides/ios/samples/measurements-on-pages-spreads.md)
- [Search and redact text in a PDF using Swift for iOS](/guides/ios/samples/search-and-redact-pdf-text.md)
- [Show author name on annotation selection in Swift for iOS](/guides/ios/samples/show-author-name-on-annotation-selection.md)
- [Programmatically add a signature to all PDF pages using Swift for iOS](/guides/ios/samples/sign-all-pdf-pages.md)
- [Store PDF annotations for multiple users in Swift for iOS](/guides/ios/samples/store-multiple-user-annotations.md)
- [PDF streaming using Swift for iOS](/guides/ios/samples/streaming-pdf.md)
- [Sticky header for PDF thumbnail view in Swift for iOS](/guides/ios/samples/sticky-header.md)
- [PDF streaming with SwiftUI for iOS](/guides/ios/samples/streaming-pdf-swiftui.md)
- [Create a custom PDF page setting view in SwiftUI for iOS](/guides/ios/samples/swiftui-settings.md)
- [Customize PDF annotation toolbar with SwiftUI for iOS](/guides/ios/samples/swiftui-annotationt-toolbar.md)
- [Custom annotation inspector with SwiftUI for iOS](/guides/ios/samples/swiftui-custom-annotation-inspector.md)
- [Import and export annotations in XFDF using Swift for iOS](/guides/ios/samples/xfdf-annotation-provider.md)
- [Add SwiftUI sidebar next to PDF view on iOS](/guides/ios/samples/swiftui-sidebar.md)
- [Show multiple PDFs with tabbed UI using Swift for iOS](/guides/ios/samples/tabbed-bar.md)
- [Add a snake game inside a PDF in Swift for iOS](/guides/ios/samples/snake.md)
- [Integrate UIStoryboard with PDFViewController in Swift for iOS](/guides/ios/samples/storyboard.md)
- [Display PDF annotations on layers in Swift for iOS](/guides/ios/samples/pdf-annotation-layers.md)
- [PDF form examples using Swift for iOS](/guides/ios/samples/pdf-forms.md)

