using aspose library (20.8) I would like to change the checked/unchecked symbol in Check Box according to my preferences, is there such an option now?
Example code which I use
documentBuilder.startTable();
final Cell cell = documentBuilder.insertCell();
StructuredDocumentTag checkBoxSDT = new StructuredDocumentTag(documentBuilder.getDocument(), SdtType.CHECKBOX, MarkupLevel.BLOCK);
// checkBoxSDT.setPlaceholderName("Check box name"); // TODO: error
checkBoxSDT.setColor(new Color(24,23,123)); // set hovered element border
checkBoxSDT.setTitle("Some custom title");
// checkBoxSDT.setCustomSymbol(....?)
cell.appendChild(checkBoxSDT)
documentBuilder.endTable();
saveDocument(documentBuilder);
Also i want to mention that when I want to set the placeholder name I get the error:
java.lang.IllegalStateException: BuildingBlock with such Name does not exist in the document glossary.
– small update:
Also, I would like to get rid of the case where after adding a CheckBox it adds break lines in a paragraph (see attachment) table_test_word_15_13_06.zip (17.4 KB)
You can remove the empty paragraph before the content control using following code example.
DocumentBuilder documentBuilder = new DocumentBuilder();
documentBuilder.startTable();
final Cell cell = documentBuilder.insertCell();
StructuredDocumentTag checkBoxSDT = new StructuredDocumentTag(documentBuilder.getDocument(), SdtType.CHECKBOX, MarkupLevel.BLOCK);
checkBoxSDT.setColor(new Color(24,23,123)); // set hovered element border
checkBoxSDT.setTitle("Some custom title");
cell.appendChild(checkBoxSDT);
documentBuilder.endTable();
cell.getFirstParagraph().remove();
documentBuilder.getDocument().save(MyDir + "out.docx");
You can use StructuredDocumentTag.Checked property to check/uncheck the checkbox.
The StructuredDocumentTag.PlaceholderName property is used to get or set the name of the BuildingBlock containing placeholder text. Note that BuildingBlock with this name Name has to be present in the GlossaryDocument otherwise InvalidOperationException will occur. Please check the code example shared here: StructuredDocumentTag - Aspose.Words for Java - API Reference
When writing about changing the symbol, I was thinking about changing the definition of the symbol, not the selection state. Ms word provides the ability to change the symbol definition.
Please see symbols.png. symbols.png (36.6 KB)
Thanks for your reply but I didn’t necessarily want just insert / delete a symbol. The MsWord program has the Developer Tab with the “Controls” field. I choose the option “Check box content control”
Then when I select my checkbox I’m able to change the definition of checked/unchecked symbol.
The checkbox keep the ability to change the state after this edition
To insert the checkbox (content control) , you can use the code example shared in my post here:
Could you please share what issue you are facing while using this code example? Please also share your input and expected output documents. We will then provide you code example according to your requirement.
I have read the proposed sources by you, but the class indicated does not provide methods that operate on objects in the way I would like.
In the attachment I enclose the expected result of the document and a photo showing the change of checkbox sign.checkbox_expected.zip (100.1 KB)
We have logged a new feature request as WORDSNET-21818 to set the checked and unchecked symbol of content control (checkbox). We will inform you via this forum thread once this feature is available. We apologize for your inconvenience.