This short tutorial describes how to insert content control in Word using Java. It includes step-by-step instructions, IDE setup, and sample code for adding various controls, including a rich text content control using Java. You will also learn how to enhance the output file by applying various parameters to the controls.
Steps to Add MS Word Content Control using Java
- Set the IDE to use Aspose.Words for Java to add content controls
- Apply the license to avoid evaluation limitations, create a Word file, and add a heading
- Insert a rich text content control, add some formatted text, and protect the control from deletion
- Add a plain text control with some text in it
- Add a checkbox to select or clear an option
- Add a drop-down list with some predefined options and select a default option
- Add a date picker control for selecting a date from a calendar
- Save the document with new controls generated through structured document tags
These steps show you how to add and customize Word document content control using Java. Import the necessary classes and modules, and create a new Word file in memory using the Document object. Use the StructuredDocumentTag for adding multiple controls with the help of the SdtType enumeration, using options such as RICH_TEXT, PLAIN_TEXT, DROP_DOWN_LIST, and DATE.
Code to Add Word Content Controls using Java
This code shows how to insert content control in Word using Java. You can set custom checked and unchecked symbols on the checkbox, enable multiline for the plain text control, and use a combo box instead of the drop-down list for priority if you want users to type their own value. There is also an option to mark the plain text control as temporary if it should disappear and leave plain text once a user edits it.
This guide explains the process to create content controls in a Word file. To convert a DOCX to JPG, refer to the article Convert DOCX to JPG using Java.