Options to Disable or Enable PDF Editing on iOS

There are several ways to modify PDF documents — for instance, by adding annotations or filling forms. The PDF format has standard restrictions (see the secured documents guide), but in addition to those built-in restrictions, PSPDFKit gives you control over how to restrict certain modifications of PDF documents.

Annotations

The following section assumes you’re familiar with annotations. If not, first see the annotations overview guide for more details.

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.

Forms

The following section assumes you’re familiar with forms. If not, first see the What Are Forms? guide for more details.

Disabling All Form Interactions

You can disable all form interactions and modifications using editableAnnotationTypes:

let configuration = PDFConfiguration {
	var editableAnnotationTypes = $0.editableAnnotationTypes
	editableAnnotationTypes?.remove(.widget)
	$0.editableAnnotationTypes = editableAnnotationTypes
}
PSPDFConfiguration *configuration = [PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) {
	NSMutableSet *editableAnnotationTypes = [builder.editableAnnotationTypes mutableCopy];
	[editableAnnotationTypes removeObject:PSPDFAnnotationStringWidget];
	builder.editableAnnotationTypes = editableAnnotationTypes;
}];

If a document doesn’t have the DocumentPermissions.annotationsAndForms and DocumentPermissions.fillForms document permissions, the result will be the same for the user, meaning they won’t be able to fill any form fields.

Disabling Specific Form Element Types

You can specify which form elements can be modified. For example, you can disable the modification of all text field form elements and allow all other form elements to be editable:

let document = Document(url: documentURL)

// Loop through all form elements from a given document and only disable text field form elements from being modified.
for formElement: FormElement in (document.formParser?.forms)! where formElement is TextFieldFormElement {
	formElement.isEditable = false;
}
PSPDFDocument *document = [[PSPDFDocument alloc] initWithURL:documentURL];

// Loop through all form elements from a given document and only disable text field form elements from being modified.
for (PSPDFFormElement *formElement in document.formParser.forms) {
	if ([formElement isKindOfClass:PSPDFTextFieldFormElement.class]) {
		formElement.editable = NO;
	}
}

Restricting Features

Document Editor

PDF documents can be modified using the Document Editor feature, which allows new page creation; page duplication; and the reordering, rotation, or deletion of pages. See the document editing guide for more details.