Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This page explains how to open a document in read-only mode programmatically.
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 getReadOnlyRecommended() property and the setPassword() 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 getReadOnlyRecommended() property is password‑secured, so if you do not set a password before applying the getReadOnlyRecommended() 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 SetPassword method.
If you need to check if a document has a write protection password that restricts it from editing, you can use the isWriteProtected() property.
The following code example shows how to make a document read-only:
If you do not want a user to open your document as read-only, you can simply set the ReadOnlyRecommened property to false or select ProtectionType as NO_PROTECTION.
The following code example shows how to remove read-only access for a document:
Q: How do I make a document read‑only with Aspose.Words for Java?
A: Load the document, obtain its WriteProtection object via document.getWriteProtection(), call setReadOnlyRecommended(true), optionally call setPassword("yourPassword"), and then save the document. This flag tells Word to open the file in read‑only mode.
Q: Can I require a password to modify the document while still allowing read‑only access?
A: Yes. After enabling getReadOnlyRecommended(), call writeProtection.setPassword("modifyPassword"). Users can open the file without a password, but any attempt to edit will prompt for the password you supplied.
Q: How can I verify whether a document is write‑protected?
A: Use the WriteProtection object’s isWriteProtected() property. It returns true when a write protection password is set; the read‑only recommendation alone does not make it true.
Q: How do I remove the read‑only recommendation or any write protection from a document?
A: Call writeProtection.setReadOnlyRecommended(false) and, to remove the password, writeProtection.setPassword(""). Then save the document. Document protection (Document.protect / Document.unprotect) is a separate feature and does not change write protection.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.