Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Sometimes you may need to limit the ability to edit a document and only allow certain actions with it. This can be useful to prevent other people from editing sensitive and confidential information in your document.
Aspose.Words allows you to restrict editing a document by setting a restriction type. In addition, Aspose.Words also enables you to specify write protection settings for a document.
This article explains how to use Aspose.Words to select a restriction type, how to add or remove protection, and how to make unrestricted editable regions.
Aspose.Words allows you to control the way you restrict the content using the ProtectionType enumeration parameter. This will enable you to select an exact type of protection such as the following:
All types are password-secured, and if this password is not entered correctly, a user will not be able to legally change the content of your document. Thus, if your document is returned to you without a requirement to provide the necessary password, this is a sign that something is wrong.
If you did not set a password when choosing the security type, other users can simply ignore the protection of your document.
Adding protection to your document is a simple process, as all you need to do is apply one of the protection methods detailed in this section.
Aspose.Words allows you to protect your documents from changes using the Protect method. This method is not a security feature and does not encrypt a document.
In Microsoft Word, you can restrict editing in a similar way using both:
The following code example shows how to add password protection to your document:
The following code example shows how to restrict editing in a document so only editing in form fields is possible:
Aspose.Words allows you to remove protection from a document with simple and direct document modification. You can either remove the document protection without knowing the actual password or provide the correct password to unlock the document by using the Unprotect method. Both removing ways have no difference.
The following code example shows how to remove protection from your document:
You can restrict editing of your document and at the same time allow changes to selected parts of it. So, anyone who opens your document will be able to access these unrestricted parts and make changes to the content.
Aspose.Words allows you to mark the parts that can be changed in your document using the StartEditableRange and EndEditableRange methods.
The following code example shows how to mark the whole document as read-only and specify editable regions in it:
You can also choose different document editing restrictions for different sections.
The following code example shows how to add a restriction for the entire document, and then remove the restriction for one of the sections:
Q: How do I apply password protection to a document?
A: Use the Document.protect(ProtectionType, password) method, passing the desired ProtectionType and a string password. The password is stored in the document and is required to remove or change the protection.
Q: Can I remove protection without knowing the password?
A: Yes. Call Document.unprotect() without arguments; this removes protection regardless of the password. Use the overload unprotect(String password) only when you want to verify the password before removing protection.
Q: Which restriction type allows users to fill only form fields?
A: Use ProtectionType.ALLOW_ONLY_FORM_FIELDS when calling Document.protect. This lets users edit form fields while keeping the rest of the document read‑only.
Q: How can I create editable regions inside a read‑only document?
A: With a DocumentBuilder, call startEditableRange() before the region and endEditableRange() after it. Content inside this range can be edited even when the document is protected with ProtectionType.READ_ONLY.
Q: How can I check whether a document is currently protected?
A: Inspect the Document.getProtectionType() property. If it returns ProtectionType.NO_PROTECTION, the document is unprotected; otherwise it returns the active restriction type.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.