Prevent Sharing of PDF Files on iOS
PSPDFKit enables you to customize the document sharing experience. To prevent your end users from sharing documents, you need to exclude the bar button items that allow sharing from your PDFViewController
’s navigation item’s leftBarButtonItems
or rightBarButtonItems
.
Here’s the list of bar button items you need to exclude from the main toolbar:
Property | Description |
---|---|
openInButtonItem |
Presents the UIDocumentInteractionController controller to open a document in other apps. |
emailButtonItem |
Presents the MFMailComposeViewController to send a document via email. |
messageButtonItem |
Presents the MFMessageComposeViewController to send a document via SMS/iMessage. |
activityButtonItem |
Presents the UIActivityViewController for various actions, including many of the above button items. |
The example below shows how to customize the main toolbar’s button to prevent sharing:
let pdfController = ... // Make sure `activityButtonItem`, `openInButtonItem`, `emailButtonItem`, and `messageButtonItem` are excluded from the `leftButtonItems` and `rightButtonItems` arrays. let leftButtonItems = [controller.settingsButtonItem, controller.outlineButtonItem] let rightButtonItems = [controller.searchButtonItem, controller.annotationButtonItem] pdfController.navigationItem.setLeftBarButtonItems(leftButtonItems, for: .document, animated: false) pdfController.navigationItem.setRightBarButtonItems(rightButtonItems, for: .document, animated: false)
For more details, see both our guide about customizing the main toolbar and the sharing examples from PSPDFKit Catalog.