This guide shows how to Java developers can use the WordsApi class to protect a DOCX [DOCX file info] document with a password via the Aspose.Words Cloud Java REST API.
Prerequisite
- Create an account and get API credentials
- Download the Aspose.Words Cloud SDK for Java to protect a Word file
- Set up a Java project and add the SDK as a dependency
Steps to Add Password to Word DOC with Java REST API
- Instantiate an object of the WordsApi class to set a password
- Read the input Word file into a byte array to protect the document
- Create a ProtectionRequestV2 object and set its parameters
- Instantiate the ProtectDocumentOnlineRequest object by providing the required arguments
- Call the ProtectDocumentOnline method to add a password
- Save the protected Word file
The steps above illustrate how to apply password protection to a Word document using the Java Low Code API. Begin by loading the source file into a byte array, then configure a ProtectionRequestV2 with the desired password and protection type. Finally, create a ProtectDocumentOnlineRequest with those settings and invoke ProtectDocumentOnline() to secure the document.
Code to Add a Password to Word Document with Java REST API
This snippet demonstrates how to set a password on a Word document with the Java Low Code API. You can choose a protection type from the ProtectionTypeEnum enumerator, such as AllowOnlyRevisions, AllowOnlyComments, AllowOnlyFormFields, ReadOnly, or NoProtection. The resulting file is stored in the cloud and can be retrieved via the Document property of the API response.
If you need to compress a Word file, see the related article: Compress Word File with Java REST API.
Keywords: how to add password protection to word document with Java Low Code API; add password to word document with NET REST API; how to set password on word document with Java Low Code API; put a password on a word document with Java REST API; add a password to word document with NET REST API.