Page 1 of 1
Add New checkbox on a bookmark
Posted:
Wed Jan 06, 2016 12:51 pm
by SameerK
I want to add a checkbox replacing a bookmark.
I am able to replace a bookmark by text following the sample provided in github but how do we replace with a checkbox?
I tried with
run = factory.createR()
CTFFCheckbox c=new CTFFCheckbox();
run.getContent().add(factory.createcTFFDatacheckbox(c));
Re: Add New checkbox on a bookmark
Posted:
Thu Jan 07, 2016 12:24 pm
by SameerK
Forget about adding to bookmark. How can we add a checkbox to document?
Re: Add New checkbox on a bookmark
Posted:
Thu Jan 07, 2016 5:52 pm
by jason
Off the top of my head, Word supports about 4 different types of checkbox:
1. the Unicode checkbox characters
2. legacy form checkbox
3. legacy activex control
4. content control checkbox.
Which do you want? Hint: a Unicode checkbox character is simplest
Re: Add New checkbox on a bookmark
Posted:
Fri Jan 08, 2016 2:24 pm
by SameerK
Thanks for replying Jason.
Any checkbox should work as long as user can check/uncheck and our application code can check/uncheck.
JFYI, we are using docx template & populating the data.
User can download the file & make changes.
Pls provide reference example for any within 4 types.
Note: Would be helpful if you can provide me reference to atleast 2 types, so just incase one of type doesn't work i can try other
Thanks in advance!
Re: Add New checkbox on a bookmark
Posted:
Fri Jan 08, 2016 8:16 pm
by jason
if you want a user to be able to check/uncheck, then the unicode character is out.
The checkbox content control is most appropriate is you are using content control databinding.
If you are not, use the legacy form checkbox.
To generate code, create a new docx in Word, add a form check box, save it, then either use the docx4j webapp or the Word Helper AddIn.
Re: Add New checkbox on a bookmark
Posted:
Sat Jan 09, 2016 11:18 am
by SameerK
Hi Jason,
I generated legacy checkbox code using webapp code generator.
I can see the xml which is generated.
Now, it contains top level document-->body-->p-->r--fldchar tags.
I am reading a docx file using docx4j API, then I tried adding a run with fldchar tag , but checkbox was not added to document.
Any reference where i can check whether i am doing it correctly?
Thanks!
Re: Add New checkbox on a bookmark
Posted:
Mon Jan 11, 2016 4:39 pm
by jason
Save your docx, unzip it, compare the XML.
Alternatively/easier, use the XMLUtils marshaltostring method to print out the contents of the p to which you added the run.