Disable PDF annotation editing for iOS users
The PDF format has standard restrictions — refer to the secured documents guide for more information. In addition to those built-in restrictions, Nutrient 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 enable 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 enabling 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, refer to 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. For example:
// Update the annotation flags.annotation.flags.update(with: .readOnly)// Update the annotation flags.annotation.flags |= ~PSPDFAnnotationFlagReadOnly;For more information, refer to 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, refer to 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.