Customize PDF Outline in Swift for iOS

Shows how to use a custom document outline controller in the document info view. Get additional resources by visiting our guide on customizing the document info in iOS.


//
// Copyright © 2021-2025 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 PSPDFKit
import PSPDFKitUI
class CustomOutlineControllerExample: Example {
override init() {
super.init()
title = "Custom Outline Controller"
contentDescription = "Shows how to use a custom outline controller in the document info."
category = .viewCustomization
priority = 100
}
override func invoke(with delegate: ExampleRunnerDelegate) -> UIViewController {
return PDFViewController(document: AssetLoader.document(for: .welcome)) {
$0.overrideClass(DocumentInfoCoordinator.self, with: CustomDocumentInfoCoordinator.self)
}
}
}
private class CustomDocumentInfoCoordinator: DocumentInfoCoordinator {
override func controller(forOption option: DocumentInfoOption) -> UIViewController? {
if option == .outline {
return CustomOutlineViewController()
} else {
return super.controller(forOption: option)
}
}
}
private class CustomOutlineViewController: UIViewController, SegmentImageProviding {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.systemYellow
let customLabel = UILabel()
customLabel.translatesAutoresizingMaskIntoConstraints = false
customLabel.text = "I am a custom outline controller"
customLabel.textAlignment = .center
view.addSubview(customLabel)
NSLayoutConstraint.activate([
customLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 20),
customLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20),
customLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor),
customLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
}
// MARK: - PSPDFSegmentImageProviding
var segmentImage: UIImage? {
return UIImage(systemName: "text.book.closed")
}
}

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