Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created August 5, 2020 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/24247a0021776683e8ccd22ddb0ea53c to your computer and use it in GitHub Desktop.
Save aspose-com-gists/24247a0021776683e8ccd22ddb0ea53c to your computer and use it in GitHub Desktop.
Make Fillable Form in Word
// Initialize new Word document
Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
// Insert Text Form Field
Aspose.Words.Fields.FormField text = builder.InsertTextInput("TextInput", Aspose.Words.Fields.TextFormFieldType.Regular, "", "Hello", 0);
// Add line break
builder.InsertBreak(Aspose.Words.BreakType.LineBreak);
// Insert Checkbox Form Field
Aspose.Words.Fields.FormField checkbox = builder.InsertCheckBox("CheckBox", true, true, 0);
checkbox.Checked = true;
builder.InsertBreak(Aspose.Words.BreakType.LineBreak);
string[] items = { "One", "Two", "Three" };
// Insert Combobox Form Field
Aspose.Words.Fields.FormField combo = builder.InsertComboBox("DropDown", items, 0);
//builder.InsertBreak(Aspose.Words.BreakType.LineBreak);
dataDir = dataDir + "InsertFormFields.docx";
doc.Save(dataDir);
// Load source DOCX file
Aspose.Words.Document doc = new Aspose.Words.Document(dataDir + "InsertFormFields.docx");
// Load form fields of the word file
Aspose.Words.Fields.FormFieldCollection documentFormFields = doc.Range.FormFields;
// Access the checkbox
Aspose.Words.Fields.FormField checkbox = documentFormFields["CheckBox"];
//Delete or remove checkbox
checkbox.Remove();
// Save updated DOCX file
doc.Save(dataDir + "DeleteField.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment