Page 1 of 1

Can I accomplish this with docx4j?

PostPosted: Thu Jul 18, 2013 1:59 pm
by bkboggy
Hey guys, I'm new to the concept of working with with files outside of simple text and pictures. I have more experience in C++ than Java. I am writing a program that so far is able to extract plain text out of a pdf using pdfbox. My next step, once I figure it out, will be to parse the extracted text into a map. For now I just have a hard-coded map of data. The map contains things such as firstName, lastName, address, dob, etc. I would like to be able to insert that data into an existing word template that has fields to enter data and titles of fields above them. I did not create the template, but I do know that it's .dot format (MS Word 2003). I successfully saved it as .docx and .rtf without losing the template formatting. I've been able to inject data into .rtf version using jrtf library by replacing %%variable%% with the data from the map; however, it doesn't give me an ability to manipulate check boxes... and it's just a hack-it way of doing things anyways, since jrtf doesn't support full editing of existing rtf files. I am wondering, if docx4j is the right tool for what I'm trying to accomplish and how I would go about it. You have to forgive me, but I've spent 4 days of nonstop reading through bunch of documentation, and at this point I just want some sane people to help me out a little bit.

As a side note: I absolutely do not care what document type my templates will be in the end, as long as they're printable in the original format. I'm just trying to help out our clerical people to lighten their load by not having to re-enter the information from the pdf forms into these word template forms we got.

Re: Can I accomplish this with docx4j?

PostPosted: Thu Jul 18, 2013 6:17 pm
by jason
Please cut/paste one of your text boxes into a new docx, save it, and upload it to our webapp (link in menu above), then view main/document.xml, and (if it is different to the below) copy/paste the XML into this thread.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting

                <w:p>
                    <w:r>
                        <w:object w:dxaOrig="1440" w:dyaOrig="1440">
                            <v:shapetype stroked="f" filled="f" o:spt="75.0" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" coordsize="21600,21600" id="_x0000_t75">
                                <v:stroke joinstyle="miter"/>
                                <v:formulas>
                                    <v:f eqn="if lineDrawn pixelLineWidth 0"/>
                                    <v:f eqn="sum @0 1 0"/>
                                    <v:f eqn="sum 0 0 @1"/>
                                    <v:f eqn="prod @2 1 2"/>
                                    <v:f eqn="prod @3 21600 pixelWidth"/>
                                    <v:f eqn="prod @3 21600 pixelHeight"/>
                                    <v:f eqn="sum @0 0 1"/>
                                    <v:f eqn="prod @6 1 2"/>
                                    <v:f eqn="prod @7 21600 pixelWidth"/>
                                    <v:f eqn="sum @8 21600 0"/>
                                    <v:f eqn="prod @7 21600 pixelHeight"/>
                                    <v:f eqn="sum @10 21600 0"/>
                                </v:formulas>
                                <v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f"/>
                                <o:lock aspectratio="t" v:ext="edit"/>
                            </v:shapetype>
                            <v:shape type="#_x0000_t75" style="width:108pt;height:21pt" id="_x0000_i1026" o:ole="">
                                <v:imagedata o:title="" r:id="rId6"/>
                            </v:shape>
                            <w:control w:name="CheckBox1" w:shapeid="_x0000_i1026" r:id="rId7"/>
                        </w:object>
                    </w:r>
                </w:p>

<!-- Same again, this time checked -->
                <w:p>
                    <w:r>
                        <w:object w:dxaOrig="1440" w:dyaOrig="1440">
                            <v:shape type="#_x0000_t75" style="width:108pt;height:21pt" id="_x0000_i1031" o:ole="">
                                <v:imagedata o:title="" r:id="rId8"/>
                            </v:shape>
                            <w:control w:name="CheckBox11" w:shapeid="_x0000_i1031" r:id="rId9"/>
                        </w:object>
                    </w:r>
                </w:p>
 
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


These are fairly unpleasant to deal with (although perhaps not so much for you, given your C++ background!).

My suggestion would be to replace these legacy activex check boxes with check box content controls. They'll be a lot easier to deal with; see setChecked in https://github.com/plutext/docx4j/blob/ ... ckbox.java

You'll need to be using the latest docx4j nightly build.

Re: Can I accomplish this with docx4j?

PostPosted: Fri Jul 19, 2013 1:08 pm
by bkboggy
Hi Jason,

I uploaded an entire row (wasn't copying only a part of it properly), so sorry for the length of the code caused by that. It looks slightly different from what you have... although formatting is in the similar domain. This is from a document that was converted from .dot to .rtf and then to .docx.

Code: Select all
        <w:document mc:Ignorable="w14 wp14">
            <w:body>
                <w:tbl>
                    <w:tblPr>
                        <w:tblW w:w="10908" w:type="dxa"/>
                        <w:tblBorders>
                            <w:top w:val="single" w:color="auto" w:sz="4" w:space="0"/>
                            <w:left w:val="single" w:color="auto" w:sz="4" w:space="0"/>
                            <w:bottom w:val="single" w:color="auto" w:sz="4" w:space="0"/>
                            <w:right w:val="single" w:color="auto" w:sz="4" w:space="0"/>
                            <w:insideH w:val="single" w:color="auto" w:sz="4" w:space="0"/>
                            <w:insideV w:val="single" w:color="auto" w:sz="4" w:space="0"/>
                        </w:tblBorders>
                        <w:tblLayout w:type="fixed"/>
                        <w:tblLook w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="0" w:noVBand="0" w:val="0000"/>
                    </w:tblPr>
                    <w:tblGrid>
                        <w:gridCol w:w="828"/>
                        <w:gridCol w:w="4797"/>
                        <w:gridCol w:w="5283"/>
                    </w:tblGrid>
                    <w:tr w:rsidTr="00695768">
                        <w:trPr>
                            <w:cantSplit/>
                            <w:trHeight w:val="600"/>
                        </w:trPr>
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:w="828" w:type="dxa"/>
                                <w:tcBorders>
                                    <w:top w:val="single" w:color="auto" w:sz="12" w:space="0"/>
                                    <w:left w:val="double" w:color="auto" w:sz="4" w:space="0"/>
                                </w:tcBorders>
                                <w:shd w:val="clear" w:color="auto" w:fill="E6E6E6"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:t>AC. NO.</w:t>
                                </w:r>
                            </w:p>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                </w:pPr>
                            </w:p>
                            <w:p>
                                <w:pPr>
                                    <w:jc w:val="center"/>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="begin">
                                        <w:ffData>
                                            <w:name w:val="Text8"/>
                                            <w:enabled/>
                                            <w:calcOnExit w:val="false"/>
                                            <w:textInput>
                                                <w:maxLength w:val="96"/>
                                                <w:format w:val="UPPERCASE"/>
                                            </w:textInput>
                                        </w:ffData>
                                    </w:fldChar>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="separate"/>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:t>%%ACN</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:t>%%</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="end"/>
                                </w:r>
                            </w:p>
                        </w:tc>
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:w="4797" w:type="dxa"/>
                                <w:tcBorders>
                                    <w:top w:val="single" w:color="auto" w:sz="12" w:space="0"/>
                                </w:tcBorders>
                                <w:shd w:val="clear" w:color="auto" w:fill="E6E6E6"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:t>NAME (LAST, FIRST MIDDLE)</w:t>
                                </w:r>
                            </w:p>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                </w:pPr>
                            </w:p>
                            <w:bookmarkStart w:name="Text7" w:id="0"/>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="begin">
                                        <w:ffData>
                                            <w:name w:val="Text7"/>
                                            <w:enabled/>
                                            <w:calcOnExit w:val="false"/>
                                            <w:textInput>
                                                <w:maxLength w:val="42"/>
                                                <w:format w:val="UPPERCASE"/>
                                            </w:textInput>
                                        </w:ffData>
                                    </w:fldChar>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="separate"/>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:t>%%LNM%%, %%FNM%% %%MNM%%</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="end"/>
                                </w:r>
                                <w:bookmarkEnd w:id="0"/>
                            </w:p>
                            <w:bookmarkStart w:name="Check28" w:id="1"/>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="begin">
                                        <w:ffData>
                                            <w:name w:val="Check28"/>
                                            <w:enabled/>
                                            <w:calcOnExit w:val="false"/>
                                            <w:checkBox>
                                                <w:sizeAuto/>
                                                <w:default w:val="false"/>
                                            </w:checkBox>
                                        </w:ffData>
                                    </w:fldChar>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:instrText xml:space="preserve"> FORMCHECKBOX </w:instrText>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="end"/>
                                </w:r>
                                <w:bookmarkEnd w:id="1"/>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:t xml:space="preserve">  REGISTERED      REFERAL NAME  </w:t>
                                </w:r>
                                <w:bookmarkStart w:name="Text9" w:id="2"/>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="begin">
                                        <w:ffData>
                                            <w:name w:val="Text9"/>
                                            <w:enabled/>
                                            <w:calcOnExit w:val="false"/>
                                            <w:textInput>
                                                <w:maxLength w:val="26"/>
                                                <w:format w:val="UPPERCASE"/>
                                            </w:textInput>
                                        </w:ffData>
                                    </w:fldChar>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="separate"/>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:t> </w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:t> </w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:t> </w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:t> </w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:t> </w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="18"/>
                                        <w:szCs w:val="18"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="end"/>
                                </w:r>
                                <w:bookmarkEnd w:id="2"/>
                            </w:p>
                        </w:tc>
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:w="5283" w:type="dxa"/>
                                <w:tcBorders>
                                    <w:top w:val="single" w:color="auto" w:sz="12" w:space="0"/>
                                    <w:right w:val="double" w:color="auto" w:sz="4" w:space="0"/>
                                </w:tcBorders>
                                <w:shd w:val="clear" w:color="auto" w:fill="E6E6E6"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="16"/>
                                        <w:szCs w:val="16"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                                        <w:b/>
                                        <w:bCs/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="12"/>
                                        <w:szCs w:val="12"/>
                                    </w:rPr>
                                    <w:t xml:space="preserve">AKA(S) </w:t>
                                </w:r>
                            </w:p>
                            <w:bookmarkStart w:name="Text8" w:id="3"/>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="begin">
                                        <w:ffData>
                                            <w:name w:val="Text8"/>
                                            <w:enabled/>
                                            <w:calcOnExit w:val="false"/>
                                            <w:textInput>
                                                <w:maxLength w:val="96"/>
                                                <w:format w:val="UPPERCASE"/>
                                            </w:textInput>
                                        </w:ffData>
                                    </w:fldChar>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="separate"/>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:noProof/>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:t>%%AKA%%</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:color w:val="000000"/>
                                        <w:sz w:val="22"/>
                                        <w:szCs w:val="22"/>
                                    </w:rPr>
                                    <w:fldChar w:fldCharType="end"/>
                                </w:r>
                                <w:bookmarkEnd w:id="3"/>
                            </w:p>
                        </w:tc>
                    </w:tr>
                </w:tbl>
                <w:p>
                    <w:bookmarkStart w:name="_GoBack" w:id="4"/>
                    <w:bookmarkEnd w:id="4"/>
                </w:p>
                <w:sectPr>
                    <w:pgSz w:w="12240" w:h="15840"/>
                    <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
                    <w:cols w:space="720"/>
                    <w:docGrid w:linePitch="360"/>
                </w:sectPr>
            </w:body>
        </w:document>



Let me know what you think.

Re: Can I accomplish this with docx4j?

PostPosted: Fri Jul 19, 2013 3:34 pm
by jason
Yeah it is quite different.

You have FORMCHECKBOX, which is another way to do it. In essence:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting

<!-- unchecked -->
     <w:r>
        <w:fldChar w:fldCharType="begin">
          <w:ffData>
            <w:name w:val="Check28"/>
            <w:enabled/>
            <w:calcOnExit w:val="0"/>
            <w:checkBox>
              <w:sizeAuto/>
              <w:default w:val="0"/>
            </w:checkBox>
          </w:ffData>
        </w:fldChar>
        <w:instrText xml:space="preserve"> FORMCHECKBOX </w:instrText>
        <w:fldChar w:fldCharType="end"/>
      </w:r>
     
<!-- checked -->
      <w:r>
        <w:fldChar w:fldCharType="begin">
          <w:ffData>
            <w:name w:val="Check28"/>
            <w:enabled/>
            <w:calcOnExit w:val="0"/>
            <w:checkBox>
              <w:sizeAuto/>
              <w:default w:val="1"/>
            </w:checkBox>
          </w:ffData>
        </w:fldChar>
        <w:instrText xml:space="preserve"> FORMCHECKBOX </w:instrText>
        <w:fldChar w:fldCharType="end"/>
      </w:r>
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


As you can see you change from unchecked to checked by setting w:default/@w:val from "0" to "1"

This is pretty straightforward to do with docx4j via its JAXB based object model.

Re: Can I accomplish this with docx4j?

PostPosted: Sun Jul 21, 2013 4:49 am
by bkboggy
How would I accomplish these tasks? I don't see a guide or tutorials page. I did notice that when I click on some links it gives sample code. I'm assuming that's how?

Re: Can I accomplish this with docx4j?

PostPosted: Sun Jul 21, 2013 5:06 am
by bkboggy
I'm just not a 100% sure how to modify the existing values. So, how I can modify a string at a specific location in the document from one value to another. Or how I can modify that check box from 0 state to 1. I've been clicking around and all I can find so far is how to create something. So, for example, when I try to see how to modify a text field, all I can find is how to create a new one (which is nice, but not what I want). Maybe it's right in front of me and I'm just missing it.

Re: Can I accomplish this with docx4j?

PostPosted: Sun Jul 21, 2013 11:14 am
by jason
If you haven't already done so, you need to read the Getting Started guide; the docx4j on a page (see our blog) may also be helpful.

First you have to retrieve the value you want to modify; Getting Started explains you can do this via XPath or TraversalUtil. Play with XPath by all means, but given its documented limitations in the JAXB RI, you might then want to move to using TraversalUtils.

Once you have the object, modification is straightforward (use the setters; and don't hesitate to look at the source code on GitHub).

The webapp mentioned earlier can generate code for you. If you examine the generated code, it will help you to understand the objects you want to manipulate. It also provides links to the source code oh GitHub for the object represented by the XML element you've chosen to generate code for.

Please feel free to post again after digesting the above.