Replace bookmark with checkbox

Hi,

When replacing a bookmark with a checkbox using the below method it is only after double clicking on the checkbox that the status (on/off) is shown.

Is this Word behaviour or did I do something wrong.

Attached are 2 images ‘generated_document.png’ (before) and ‘after_double_click_in_a_text_field.png’ (after).

Thanks,

Marcel

try
{
    final Bookmark bookmark = this.doc.getRange().getBookmarks().get(bookMark);
    this.builder.moveTo(bookmark.getBookmarkStart());
    this.builder.insertCheckBox(name, defaultValue, size);
    bookmark.setText("");
    bookmark.remove();
}
catch (final Exception e ) {
    if (this.debugMissingBookmarks)
    {
        Debug.log("Missing bookmark " + bookMark);
    }
}

Hi Marcel,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If your document is protected with ALLOW_ONLY_FORM_FIELDS protection type, you can change the status (on/off) of check-box.

Could you please attach your input, output and expected output Word documents here for our reference? We will then provide you more information about your query.

Hi,

Attached are the before and after docs.

What I want to see is as in the screenshot ‘after_double_click_in_a_text_field.png’ but without the double click.

I hope this makes things more clear.

Hi Marcel,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. MS Word does not allow to insert check box (legacy form control) in the header of document.

We suggest you please insert content control of type CHECKBOX in the header of document. Please check following code example and read following documentation link for your kind reference. Hope this helps you.

Working with Content Control (SDT)

Document doc = new Document(MyDir + "doc_before.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToBookmark("chkSurvey");
StructuredDocumentTag SdtCheckBox = new StructuredDocumentTag(doc, SdtType.CHECKBOX, MarkupLevel.INLINE);
// Insert content control into the document
builder.insertNode(SdtCheckBox);
builder.moveToBookmark("chkIntermediate");
builder.insertNode(SdtCheckBox.deepClone(true));
builder.moveToBookmark("chkFinal");
builder.insertNode(SdtCheckBox.deepClone(true));
doc.save(MyDir + "Out.docx");

Hi,
Because you mention ‘legacy form control’ I have the following question:
Does this mean that this will work only with later versions of Word or with any version?
Thanks,
Marcel

Hi Marcel,

Thanks for your inquiry. Please open your input document in MS Word and try to insert check box (legacy form control) in the header of document. MS Word does not allow to insert legacy form control in the header of document. Please check the attached image for detail. So, you cannot insert legacy form control in the header of document using MS Word and Aspose.Words.

Please insert content control of type CHECKBOX in the header of document as shared in my previous post.