Page 1 of 1

need editable check box

PostPosted: Tue Jul 03, 2018 5:07 pm
by pawan
hi all,

I am trying to get editable check box on MS WORD but always there is some problem occurs with my code , i already tried with the input XML and HTML but no luck.

New with DOCX4J.

Need help, provide me a sample code and XML for this.

Re: need editable check box

PostPosted: Tue Jul 03, 2018 9:09 pm
by pawan
hi all,

Is there any needful information i can share and please give reply fast

Re: need editable check box

PostPosted: Wed Jul 04, 2018 12:42 pm
by jason
You don't provide any details at all on what you are doing so I can only provide general guidance.

You can add a checkbox control using this OpenDoPE Word AddIn: https://github.com/plutext/OpenDoPE-NoX ... n-1_02.exe
in Word 2013/2016
(add a multiple choice question accepting true/false, then click the "add as checkbox" button)

And docx4j can bind that: https://github.com/plutext/docx4j/blob/ ... geXML.java

Up until just now, it didn't set the w14:checked property https://github.com/plutext/docx4j/commi ... f7f48825be but you would still see a symbol on the document surface.

You can author a checkbox control in recent versions of Word. I haven't checked whether docx4j will bind that without the OpenDoPE stuff present, but if it can't, that would be trivial to support.

Re: need editable check box

PostPosted: Wed Jul 04, 2018 7:55 pm
by pawan
hi jason,

i got this error in my code

14:20:44.114 [main] DEBUG org.docx4j.XmlUtils - name: {http://schemas.openxmlformats.org/wordprocessingml/2006/main}t
14:20:44.114 [main] DEBUG org.docx4j.TraversalUtil - getting children of org.docx4j.wml.Text
14:20:44.114 [main] ERROR o.d.m.d.CustomXmlDataStoragePartSelector - FATAL. Couldn't find CustomXmlDataStoragePart
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't find CustomXmlDataStoragePart! exiting..
at org.docx4j.Docx4J.bind(Docx4J.java:414)
at org.docx4j.Docx4J.bind(Docx4J.java:383)
at org.docx4j.Docx4J.bind(Docx4J.java:376)
at tryWordCheck.twc.WordCheckBoxClass.main(WordCheckBoxClass.java:146)

and if i don't want to install this app on my server which you suggested here ,is there any other way to resolve the above mention error?
"You can add a checkbox control using this OpenDoPE Word AddIn: https://github.com/plutext/OpenDoPE-NoX ... n-1_02.exe
in Word 2013/2016
(add a multiple choice question accepting true/false, then click the "add as checkbox" button)"

Re: need editable check box

PostPosted: Wed Jul 04, 2018 8:12 pm
by jason
pawan wrote:FATAL. Couldn't find CustomXmlDataStoragePart


Seems like you don't have the Custom XML Part in your docx, but you haven't attached it, so who knows?

Re: need editable check box

PostPosted: Wed Jul 04, 2018 8:49 pm
by pawan
please find attachment

now getting below issue from this code.

15:10:38.393 [main] DEBUG org.docx4j.openpackaging.parts.Part - null
15:10:38.393 [main] DEBUG org.docx4j.openpackaging.parts.Part - setPackage to null called for org.docx4j.openpackaging.parts.relationships.RelationshipsPart
15:10:38.393 [main] DEBUG org.docx4j.openpackaging.parts.Part - null
15:10:38.393 [main] DEBUG org.docx4j.openpackaging.io3.Load3 -
For Relationship Id=rId1 Source is /word/header4.xml, Target is media/image2.png, type: http://schemas.openxmlformats.org/offic ... hips/image
15:10:38.393 [main] INFO org.docx4j.openpackaging.io3.Load3 - package read; elapsed time: 3521 ms
[Fatal Error] :1:15: The prefix "w14" for element "w14:checkbox" is not bound.
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Problems creating a org.w3c.dom.Document for the passed input stream.
at org.docx4j.Docx4J.bind(Docx4J.java:373)
at tryWordCheck.twc.WordCheckBoxClass.main(WordCheckBoxClass.java:146)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 15; The prefix "w14" for element "w14:checkbox" is not bound.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at org.docx4j.Docx4J.bind(Docx4J.java:371)
... 1 more

Re: need editable check box

PostPosted: Wed Jul 04, 2018 9:21 pm
by pawan
XML i am using

<w14:checkbox>
<w14:checked w14:val="1"/>
<w14:checkedState w14:val="2612" w14:font="MS Gothic"/>
<w14:uncheckedState w14:val="2610" w14:font="MS Gothic"/>
</w14:checkbox>

Re: need editable check box

PostPosted: Wed Jul 04, 2018 9:40 pm
by jason
I think you need to take a step back and understand how XML content control data binding works, before you try to bind a checkbox content control.

The checkbox content control (aka w:sdt) would typically be in your main document part. The w14 checkbox xml is in w:sdt/w:sdtPr.

The content control is bound via XPath to some XML element (in a Custom XML part); that XML element should contain the string true or false (true is check box checked).