Configure PDF View Controllers on iOS

A PDFConfiguration defines the behavior of a PDFViewController. It uses the builder pattern from PDFConfigurationBuilder(opens in a new tab) to create an immutable copy using a closure.

The following code demonstrates a typical use case:

let document = Document(url: documentURL)
// The configuration building closure is passed to the `Document` initializer as a trailing closure.
let controller = PDFViewController(document: document) {
$0.thumbnailBarMode = .none
$0.shouldShowUserInterfaceOnViewWillAppear = false
$0.isPageLabelEnabled = false
}

PDFViewController contains a shortcut to create and set a new PDFConfiguration object — updateConfiguration(builder:)(opens in a new tab) — based on the current settings. After setting the new configuration object, the view controller will automatically invoke reloadData()(opens in a new tab) to refresh its state.

Certain properties can be updated without a full state reload using updateConfigurationWithoutReloading(builder:)(opens in a new tab). Be careful though, since PSPDFKit doesn’t warn you if you change a property that would require a state reload, as the view controller could get into an invalid state using this method.

Here’s an example:

controller.updateConfigurationWithoutReloading {
$0.isTextSelectionEnabled = !isAutoplaying
$0.isScrollOnEdgeTapEnabled = !isAutoplaying
}