View Controller Configuration

A PDFConfiguration defines the behavior of a PDFViewController. It uses the builder pattern from PDFConfigurationBuilder to create an immutable copy using a closure.

A typical use case is the following:

Copy
1
2
3
4
5
6
7
let document = Document(url: documentURL)
// The configuration building closure is passed as a trailing closure to the Document initializer.
let controller = PDFViewController(document: document) {
    $0.thumbnailBarMode = .none
    $0.shouldShowUserInterfaceOnViewWillAppear = false
    $0.isPageLabelEnabled = false
}
Copy
1
2
3
4
5
6
PSPDFDocument *document = [[PSPDFDocument alloc] initWithURL:documentURL];
PSPDFViewController *controller = [[PSPDFViewController alloc] initWithDocument:document configuration:[PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) {
    builder.thumbnailBarMode = PSPDFThumbnailBarModeNone;
    builder.shouldShowUserInterfaceOnViewWillAppear = NO;
    builder.pageLabelEnabled = NO;
}]];

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

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

Example:

Copy
1
2
3
4
controller.updateConfigurationWithoutReloading {
    $0.isTextSelectionEnabled = !isAutoplaying
    $0.isScrollOnEdgeTapEnabled = !isAutoplaying
}
Copy
1
2
3
4
[controller updateConfigurationWithoutReloadingWithBuilder:^(PSPDFConfigurationBuilder *builder) {
    builder.textSelectionEnabled = !self.isAutoplaying;
    builder.scrollOnEdgeTapEnabled = !self.isAutoplaying;
}];