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 Document.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 in Node.js?
A: Use the Document.protect method, passing the desired ProtectionType and a password string. The password is stored in the document properties and will be required to modify the protected content.
Q: Can I remove protection from a document without knowing the password?
A: No. The Document.unprotect method requires the correct password if one was set. If the document was protected without a password, calling unprotect() without arguments will remove the protection.
Q: How can I determine whether a document is protected and which protection type is applied?
A: Check the Document.protectionType property. It returns a value from the ProtectionType enumeration, such as ReadOnly, AllowOnlyFormFields, or NoProtection.
Q: How do I create unrestricted editable regions inside a read‑only document?
A: Use a DocumentBuilder to call StartEditableRange before the region and EndEditableRange after it. Content inside this range can be edited even when the rest of the document is read‑only.
Q: Is it possible to change the protection type of an already protected document?
A: Yes, but you must first call Document.unprotect with the current password, then apply a new protection using Document.protect with the desired ProtectionType.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.