Setting the Initial Page Selection When Sharing

Q: How do I set the initial page selection when sharing a document but still allow the user to choose any pages?

A: You can set the initially selected pages by setting properties on a PDFDocumentSharingViewController before it appears. Leave all the options available in the sharing configuration (perhaps use the default configuration).

For example, to initially select the first five pages:

let sharingViewController: PDFDocumentSharingViewController = ...
sharingViewController.selectedPageSelectionOption = .range
sharingViewController.shareablePageRange = NSRange(location: 0, length: 5)
PSPDFDocumentSharingViewController *sharingViewController = ...
sharingViewController.selectedPageSelectionOption = PSPDFDocumentSharingPagesOptionRange;
sharingViewController.shareablePageRange = NSMakeRange(0, 5);

The shareablePageRange sets the initial range selected by PSPDFDocumentSharingPagesOptionRange. If the user change pages with the picker or chooses a different option like current page, then the shareablePageRange property of the PDFDocumentSharingViewController will be updated.

If you want to initially select only the current page, set selectedPageSelectionOption to .current and there is no need to set shareablePageRange.

This has been tested with PSPDFKit 10.1 for iOS.