Disabling Annotation Editing on iOS
The PDF format has standard restrictions (see the Secured Documents guide). In addition to those built-in restrictions, PSPDFKit gives you control over how to restrict modifications to annotations.
Disabling the Modification of All Annotation Types
You can disable all annotation modifications using PDFConfiguration
by setting the editableAnnotationTypes
property to nil
. This will prevent users from adding new annotations and editing existing ones:
let configuration = PDFConfiguration { $0.editableAnnotationTypes = nil }
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { builder.editableAnnotationTypes = nil; }];
Enabling Modifications Only for Specific Annotation Types
You can control which annotation types are editable, and you can specify their types in editableAnnotationTypes
. For example, you can allow only the modification of ink annotations:
let configuration = PDFConfiguration { $0.editableAnnotationTypes = [.ink] }
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) {
builder.editableAnnotationTypes = [NSSet setWithArray:@[PSPDFAnnotationStringInk]]; // Only ink annotations are editable.
}];
Disabling Adding New Annotations but Allowing Modification of Existing Ones
Hiding your PDFViewController
’s annotationButtonItem
from the toolbar will prevent users from adding new annotations, but it won’t stop them from editing or deleting existing ones:
// Notice that `pdfController.annotationButtonItem` isn't included. pdfController.navigationItem.setRightBarButtonItems([pdfController.thumbnailsButtonItem, pdfController.outlineButtonItem, pdfController.searchButtonItem, pdfController.activityButtonItem], for: .document, animated: false)
// Notice that `pdfController.annotationButtonItem` isn't included.
[pdfController.navigationItem setRightBarButtonItems:@[pdfController.thumbnailsButtonItem, pdfController.outlineButtonItem, pdfController.searchButtonItem, pdfController.activityButtonItem] forViewMode:PSPDFViewModeDocument animated:NO];
For more information, see the guide on configuring editable/visible annotation types.
Disabling the Modification of a Specific Annotation
You can disable the modification of a specific annotation by updating its flags
property to use Annotation.Flag.readOnly
, like so:
// Update the annotation flags.
annotation.flags.update(with: .readOnly)
// Update the annotation flags.
annotation.flags |= ~PSPDFAnnotationFlagReadOnly;
For more information, see the guide on annotation flags.
Disabling Adding Annotations Using Menus
You can add annotations using the menu that shows up when you long press on empty space. This menu contains the Paste action and tools for creating different annotations. To disable this menu entirely, set the isCreateAnnotationMenuEnabled
configuration property to false
:
let configuration = PDFConfiguration { $0.isCreateAnnotationMenuEnabled = false }
Text markup annotations can also be created by selecting text. For example, when you select text in a document, you can highlight it. To exclude the highlight tool from the text selection menu, use the contentMenuConfiguration
property:
let configuration = PDFConfiguration { $0.contentMenuConfiguration = ContentMenuConfiguration { $0.annotationToolChoices = { _, _, _, defaultChoices in defaultChoices.filter { $0 != .highlight } } } }
To learn more about different menus and how to customize them, check out our guide on customizing menus.
Disabling Drag and Drop
PDFs can be modified using drag and drop. For example, you can drag and drop text, images, and even other PDF documents to create annotations within a document. You can disable drag and drop by configuring your DragAndDropConfiguration
:
let dragAndDropConfiguration = DragAndDropConfiguration { $0.acceptedDropTypes = [] $0.allowedDropTargets = [] } let configuration = PDFConfiguration { $0.dragAndDropConfiguration = dragAndDropConfiguration }
PSPDFDragAndDropConfiguration *dragAndDropConfiguration = [PSPDFDragAndDropConfiguration configurationWithBuilder:^(PSPDFDragAndDropConfigurationBuilder * builder) { builder.acceptedDropTypes = PSPDFDropTypeNone; builder.allowedDropTargets = PSPDFDropTargetNone; }]; PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { builder.dragAndDropConfiguration = dragAndDropConfiguration; }];
For more information, refer to the guide on drag and drop.