Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Sometimes, you may have a document that needs a review, but you do not want reviewers to randomly modify your content. Aspose.Words allows you to make the permission of your document read-only so that the content can be copied or read, but not modified. This will prevent content from being removed or added to your document.
This article explains how to make a document read-only.
Aspose.Words has the public class WriteProtection that specifies write protection settings for a document. You do not create instances of this class directly.
Write protection shows whether the author has recommended opening a document as read-only and/or requiring a password to modify the document.
Aspose.Words allows you to make a document read-only to restrict editing by using the read_only_recommended property and the set_password method.
In Microsoft Word, you can create a Read-Only document in a similar way using both:
Users can also restrict document editing by selecting ProtectionType as READ_ONLY, but this is another feature that provides more advanced protection capabilities. There is such a function in Microsoft Word, respectively, it is implemented in Aspose.Words.
ProtectionType will be described in detail in one of the following articles – “Restrict Document Editing”.
The read_only_recommended property is password-secured, so if you do not set a password before applying the read_only_recommended property, then other users can simply open the document as if it were unprotected. You access the document protection settings and set a write protection password via the set_password method.
If you need to check if a document has a write protection password that restricts it from editing, you can use the is_write_protected property.
The following code example shows how to make a document read-only:
import aspose.words as aw
doc = aw.Document()
builder = aw.DocumentBuilder(doc)
builder.write("Open document as read-only")
# Enter a password that's up to 15 characters long.
doc.write_protection.set_password("MyPassword")
# Make the document as read-only.
doc.write_protection.read_only_recommended = True
# Apply write protection as read-only.
doc.protect(aw.ProtectionType.READ_ONLY)
doc.save(docs_base.artifacts_dir + "DocumentProtection.ReadOnlyProtection.docx")If you do not want a user to open your document as read-only, you can simply set the read_only_recommended property to False or select ProtectionType as NO_PROTECTION.
The following code example shows how to remove read-only access for a document:
import aspose.words as aw
doc = aw.Document()
# Enter a password that's up to 15 characters long.
doc.write_protection.set_password("MyPassword")
# Remove the read-only option.
doc.write_protection.read_only_recommended = False
# Apply write protection without any protection.
doc.protect(aw.ProtectionType.NO_PROTECTION)
doc.save(docs_base.artifacts_dir + "DocumentProtection.RemoveReadOnlyRestriction.docx")Q: How do I make a document read‑only using Aspose.Words for Python?
A: Set a password with doc.write_protection.set_password("yourPassword"), enable the read‑only recommendation with doc.write_protection.read_only_recommended = True, and then apply the protection using doc.protect(aw.ProtectionType.READ_ONLY).
Q: Is a password required to use the read_only_recommended property?
A: No, the property can be set without a password, but without a password any user can remove the recommendation by clearing the property. Adding a password makes the setting harder to bypass.
Q: What is the difference between read_only_recommended and doc.protect(ProtectionType.READ_ONLY)?
A: read_only_recommended only suggests that the document should be opened as read‑only; it does not enforce protection. doc.protect(ProtectionType.READ_ONLY) actually enforces the read‑only mode and, when combined with a password, prevents editing unless the password is supplied.
Q: How can I remove the read‑only restriction from a document?
A: Set doc.write_protection.read_only_recommended = False and call doc.protect(aw.ProtectionType.NO_PROTECTION). This clears both the recommendation and any applied protection.
Q: Does making a document read‑only stop users from copying its content?
A: No. Read‑only protection only prevents modifications to the document. Users can still select, copy, and paste the content unless additional restrictions (e.g., encryption) are applied.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.