public class ProtectionType
Example:
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 int | ALLOW_ONLY_COMMENTS | |
User can only modify comments in the document.
|
||
static final int | ALLOW_ONLY_FORM_FIELDS | |
User can only enter data in the form fields in the document.
|
||
static final int | ALLOW_ONLY_REVISIONS | |
User can only add revision marks to the document.
|
||
static final int | READ_ONLY | |
No changes are allowed to the document. Available since Microsoft Word 2003.
|
||
static final int | NO_PROTECTION | |
The document is not protected.
|
public static final int ALLOW_ONLY_COMMENTS
public static final int ALLOW_ONLY_FORM_FIELDS
public static final int ALLOW_ONLY_REVISIONS
public static final int READ_ONLY
public static final int NO_PROTECTION