com.aspose.words

Class ProtectionType

  • java.lang.Object
    • com.aspose.words.ProtectionType
public class ProtectionType 
extends java.lang.Object

Utility class containing constants. Protection type for a document.

Example:

Shows how to turn off protection for a section.
Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Section 1. Hello world!");
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

builder.writeln("Section 2. Hello again!");
builder.write("Please enter text here: ");
builder.insertTextInput("TextInput1", TextFormFieldType.REGULAR, "", "Placeholder text", 0);

// Apply write protection to every section in the document.
doc.protect(ProtectionType.ALLOW_ONLY_FORM_FIELDS);

// Turn off write protection for the first section.
doc.getSections().get(0).setProtectedForForms(false);

// In this output document, we will be able to edit the first section freely,
// and we will only be able to edit the contents of the form field in the second section.
doc.save(getArtifactsDir() + "Section.Protect.docx");

Field Summary
static final intALLOW_ONLY_COMMENTS = 1
User can only modify comments in the document.
static final intALLOW_ONLY_FORM_FIELDS = 2
User can only enter data in the form fields in the document.
static final intALLOW_ONLY_REVISIONS = 0
User can only add revision marks to the document.
static final intREAD_ONLY = 3
No changes are allowed to the document. Available since Microsoft Word 2003.
static final intNO_PROTECTION = -1
The document is not protected.
 

    • Field Detail

      • ALLOW_ONLY_COMMENTS = 1

        public static final int ALLOW_ONLY_COMMENTS
        User can only modify comments in the document.
      • ALLOW_ONLY_FORM_FIELDS = 2

        public static final int ALLOW_ONLY_FORM_FIELDS
        User can only enter data in the form fields in the document.
      • ALLOW_ONLY_REVISIONS = 0

        public static final int ALLOW_ONLY_REVISIONS
        User can only add revision marks to the document.
      • READ_ONLY = 3

        public static final int READ_ONLY
        No changes are allowed to the document. Available since Microsoft Word 2003.
      • NO_PROTECTION = -1

        public static final int NO_PROTECTION
        The document is not protected.