Page 1 of 1

unreadable content whenever there is table modification

PostPosted: Sun Jul 18, 2021 5:22 pm
by 12AM
Hello,
Whenever I run my program the resulted document will always have unreadable content. tried to find the root of the issue and it will always happen whenever I try to modify a table.
my current table edit code:
Code: Select all
Tr workingRow = (Tr) XmlUtils.deepCopy(templateRow);
List<?> textElements = getTargetElements(workingRow, Text.class);
      for (Object object : textElements) {
         Text text = (Text) object;
         textBefore = text.getValue();
         String replacementValue = (String) replacements.get(textBefore);
         if (replacementValue != null) {
            text.setValue(replacementValue);
         }
      }
reviewtable.getContent().add(workingRow);

replacementValue has texts that needs to be replace since I can't use VariableReplace as it is a dynamic table.

libraries used: docx4j 8.3.1 and docx4j-JAXB-MOXy 8.3.1

Re: unreadable content whenever there is table modification

PostPosted: Sun Jul 18, 2021 5:30 pm
by 12AM
the method code of getTargetElements:
Code: Select all
private List<Object> getTargetElements(Object source, Class<?> targetClass) {
      List<Object> result = new ArrayList<Object>();
      Object target = XmlUtils.unwrap(source);
      // if (target.getClass().equals(targetClass)) {
      if (targetClass.isAssignableFrom(target.getClass())) {
         result.add((Object) target);
      } else if (target instanceof ContentAccessor) {
         List<?> children = ((ContentAccessor) target).getContent();
         for (Object child : children) {
            result.addAll(getTargetElements(child, targetClass));
         }
      }
      return result;
   }


same code has been used for getting the tables in the document.

Re: unreadable content whenever there is table modification

PostPosted: Tue Jul 20, 2021 7:47 am
by jason
Use XmlUtils.marshaltoString on your Tr object to compare before and after. Feel free to post the results here.

One thing to watch out for: Word requires a tc to contain at least one paragraph (which can be empty).

Re: unreadable content whenever there is table modification

PostPosted: Wed Jul 21, 2021 5:05 pm
by 12AM
default row xml:
Code: Select all
<w:tr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing">
   <w:trPr>
      <w:trHeight w:val="483"/>
   </w:trPr>
   <w:tc>
      <w:tcPr>
         <w:tcW w:w="744" w:type="dxa"/>
         <w:vAlign w:val="center"/>
      </w:tcPr>
      <w:p>
         <w:pPr>
            <w:tabs>
               <w:tab w:val="left" w:pos="1047"/>
            </w:tabs>
            <w:bidi/>
            <w:rPr>
               <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
               <w:sz w:val="28"/>
               <w:szCs w:val="28"/>
               <w:rtl/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
               <w:noProof/>
               <w:sz w:val="28"/>
               <w:szCs w:val="28"/>
               <w:rtl/>
               <w:lang w:val="en-GB" w:eastAsia="en-GB"/>
            </w:rPr>
            <mc:AlternateContent>
               <mc:Choice Requires="wps">
                  <w:drawing>
                     <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="false" relativeHeight="251663360" behindDoc="false" locked="false" layoutInCell="false" allowOverlap="true" wp14:anchorId="7C8D7BB9" wp14:editId="5AD06689">
                        <wp:simplePos x="0" y="0"/>
                        <wp:positionH relativeFrom="page">
                           <wp:posOffset>169545</wp:posOffset>
                        </wp:positionH>
                        <wp:positionV relativeFrom="page">
                           <wp:posOffset>58420</wp:posOffset>
                        </wp:positionV>
                        <wp:extent cx="127000" cy="127000"/>
                        <wp:effectExtent l="0" t="0" r="6350" b="6350"/>
                        <wp:wrapNone/>
                        <wp:docPr id="4" name="Rectangle 4" xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart"/>
                        <wp:cNvGraphicFramePr xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
                           <a:graphicFrameLocks/>
                        </wp:cNvGraphicFramePr>
                        <a:graphic xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
                           <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                              <wps:wsp xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                 <wps:cNvSpPr>
                                    <a:spLocks noChangeArrowheads="true"/>
                                 </wps:cNvSpPr>
                                 <wps:spPr bwMode="auto">
                                    <a:xfrm>
                                       <a:off x="0" y="0"/>
                                       <a:ext cx="127000" cy="127000"/>
                                    </a:xfrm>
                                    <a:prstGeom prst="rect">
                                       <a:avLst/>
                                    </a:prstGeom>
                                    <a:solidFill>
                                       <a:srgbClr val="41459E"/>
                                    </a:solidFill>
                                    <a:ln>
                                       <a:noFill/>
                                    </a:ln>
                                    <a:extLst>
                                       <a:ext uri="{91240B29-F687-4F45-9708-019B960494DF}">
                                          <a14:hiddenLine w="0">
                                             <a:solidFill>
                                                <a:srgbClr val="000000"/>
                                             </a:solidFill>
                                             <a:miter lim="800000"/>
                                             <a:headEnd/>
                                             <a:tailEnd/>
                                          </a14:hiddenLine>
                                       </a:ext>
                                    </a:extLst>
                                 </wps:spPr>
                                 <wps:bodyPr rot="0" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" anchor="t" anchorCtr="false" upright="true">
                                    <a:noAutofit/>
                                 </wps:bodyPr>
                              </wps:wsp>
                           </a:graphicData>
                        </a:graphic>
                        <wp14:sizeRelH relativeFrom="page">
                           <wp14:pctWidth>0</wp14:pctWidth>
                        </wp14:sizeRelH>
                        <wp14:sizeRelV relativeFrom="page">
                           <wp14:pctHeight>0</wp14:pctHeight>
                        </wp14:sizeRelV>
                     </wp:anchor>
                  </w:drawing>
               </mc:Choice>
               <mc:Fallback>
                  <w:pict>
                     <v:rect style="position:absolute;margin-left:13.35pt;margin-top:4.6pt;width:10pt;height:10pt;z-index:251663360;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:page;mso-position-vertical:absolute;mso-position-vertical-relative:page;mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;mso-height-relative:page;v-text-anchor:top" id="Rectangle 4" o:spid="_x0000_s1026" o:allowincell="f" stroked="f" strokeweight="0" fillcolor="#41459e" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:xvml="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:pvml="urn:schemas-microsoft-com:office:powerpoint">
                        <w10:wrap anchorx="page" anchory="page"/>
                     </v:rect>
                  </w:pict>
               </mc:Fallback>
            </mc:AlternateContent>
         </w:r>
      </w:p>
   </w:tc>
   <w:tc>
      <w:tcPr>
         <w:tcW w:w="6654" w:type="dxa"/>
         <w:vAlign w:val="center"/>
      </w:tcPr>
      <w:p>
         <w:pPr>
            <w:tabs>
               <w:tab w:val="left" w:pos="1047"/>
            </w:tabs>
            <w:bidi/>
            <w:rPr>
               <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
               <w:sz w:val="28"/>
               <w:szCs w:val="28"/>
               <w:rtl/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
               <w:sz w:val="28"/>
               <w:szCs w:val="28"/>
            </w:rPr>
            <w:t>${content}</w:t>
         </w:r>
      </w:p>
   </w:tc>
</w:tr>


table after alteration:
Code: Select all
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing">
   <w:tblPr>
      <w:tblStyle w:val="TableGrid"/>
      <w:tblpPr w:leftFromText="180" w:rightFromText="180" w:vertAnchor="text" w:horzAnchor="margin" w:tblpXSpec="center" w:tblpY="224"/>
      <w:bidiVisual/>
      <w:tblW w:w="0" w:type="auto"/>
      <w:tblBorders>
         <w:top w:val="none" w:color="auto" w:sz="0" w:space="0"/>
         <w:left w:val="none" w:color="auto" w:sz="0" w:space="0"/>
         <w:bottom w:val="none" w:color="auto" w:sz="0" w:space="0"/>
         <w:right w:val="none" w:color="auto" w:sz="0" w:space="0"/>
         <w:insideH w:val="none" w:color="auto" w:sz="0" w:space="0"/>
         <w:insideV w:val="none" w:color="auto" w:sz="0" w:space="0"/>
      </w:tblBorders>
      <w:tblLook w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1" w:val="04A0"/>
   </w:tblPr>
   <w:tblGrid>
      <w:gridCol w:w="744"/>
      <w:gridCol w:w="6654"/>
   </w:tblGrid>
   <w:tr>
      <w:trPr>
         <w:trHeight w:val="483"/>
      </w:trPr>
      <w:tc>
         <w:tcPr>
            <w:tcW w:w="744" w:type="dxa"/>
            <w:vAlign w:val="center"/>
         </w:tcPr>
         <w:p>
            <w:pPr>
               <w:tabs>
                  <w:tab w:val="left" w:pos="1047"/>
               </w:tabs>
               <w:bidi/>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
                  <w:rtl/>
               </w:rPr>
            </w:pPr>
            <w:r>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:noProof/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
                  <w:rtl/>
                  <w:lang w:val="en-GB" w:eastAsia="en-GB"/>
               </w:rPr>
               <mc:AlternateContent>
                  <mc:Choice Requires="wps">
                     <w:drawing>
                        <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="false" relativeHeight="251663360" behindDoc="false" locked="false" layoutInCell="false" allowOverlap="true" wp14:anchorId="7C8D7BB9" wp14:editId="5AD06689">
                           <wp:simplePos x="0" y="0"/>
                           <wp:positionH relativeFrom="page">
                              <wp:posOffset>169545</wp:posOffset>
                           </wp:positionH>
                           <wp:positionV relativeFrom="page">
                              <wp:posOffset>58420</wp:posOffset>
                           </wp:positionV>
                           <wp:extent cx="127000" cy="127000"/>
                           <wp:effectExtent l="0" t="0" r="6350" b="6350"/>
                           <wp:wrapNone/>
                           <wp:docPr id="4" name="Rectangle 4" xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart"/>
                           <wp:cNvGraphicFramePr xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
                              <a:graphicFrameLocks/>
                           </wp:cNvGraphicFramePr>
                           <a:graphic xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
                              <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                 <wps:wsp xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                    <wps:cNvSpPr>
                                       <a:spLocks noChangeArrowheads="true"/>
                                    </wps:cNvSpPr>
                                    <wps:spPr bwMode="auto">
                                       <a:xfrm>
                                          <a:off x="0" y="0"/>
                                          <a:ext cx="127000" cy="127000"/>
                                       </a:xfrm>
                                       <a:prstGeom prst="rect">
                                          <a:avLst/>
                                       </a:prstGeom>
                                       <a:solidFill>
                                          <a:srgbClr val="41459E"/>
                                       </a:solidFill>
                                       <a:ln>
                                          <a:noFill/>
                                       </a:ln>
                                       <a:extLst>
                                          <a:ext uri="{91240B29-F687-4F45-9708-019B960494DF}">
                                             <a14:hiddenLine w="0">
                                                <a:solidFill>
                                                   <a:srgbClr val="000000"/>
                                                </a:solidFill>
                                                <a:miter lim="800000"/>
                                                <a:headEnd/>
                                                <a:tailEnd/>
                                             </a14:hiddenLine>
                                          </a:ext>
                                       </a:extLst>
                                    </wps:spPr>
                                    <wps:bodyPr rot="0" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" anchor="t" anchorCtr="false" upright="true">
                                       <a:noAutofit/>
                                    </wps:bodyPr>
                                 </wps:wsp>
                              </a:graphicData>
                           </a:graphic>
                           <wp14:sizeRelH relativeFrom="page">
                              <wp14:pctWidth>0</wp14:pctWidth>
                           </wp14:sizeRelH>
                           <wp14:sizeRelV relativeFrom="page">
                              <wp14:pctHeight>0</wp14:pctHeight>
                           </wp14:sizeRelV>
                        </wp:anchor>
                     </w:drawing>
                  </mc:Choice>
                  <mc:Fallback>
                     <w:pict>
                        <v:rect style="position:absolute;margin-left:13.35pt;margin-top:4.6pt;width:10pt;height:10pt;z-index:251663360;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:page;mso-position-vertical:absolute;mso-position-vertical-relative:page;mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;mso-height-relative:page;v-text-anchor:top" id="Rectangle 4" o:spid="_x0000_s1026" o:allowincell="f" stroked="f" strokeweight="0" fillcolor="#41459e" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:xvml="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:pvml="urn:schemas-microsoft-com:office:powerpoint">
                           <w10:wrap anchorx="page" anchory="page"/>
                        </v:rect>
                     </w:pict>
                  </mc:Fallback>
               </mc:AlternateContent>
            </w:r>
         </w:p>
      </w:tc>
      <w:tc>
         <w:tcPr>
            <w:tcW w:w="6654" w:type="dxa"/>
            <w:vAlign w:val="center"/>
         </w:tcPr>
         <w:p>
            <w:pPr>
               <w:tabs>
                  <w:tab w:val="left" w:pos="1047"/>
               </w:tabs>
               <w:bidi/>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
                  <w:rtl/>
               </w:rPr>
            </w:pPr>
            <w:r>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
               </w:rPr>
               <w:t>text 1</w:t>
            </w:r>
         </w:p>
      </w:tc>
   </w:tr>
   <w:tr>
      <w:trPr>
         <w:trHeight w:val="483"/>
      </w:trPr>
      <w:tc>
         <w:tcPr>
            <w:tcW w:w="744" w:type="dxa"/>
            <w:vAlign w:val="center"/>
         </w:tcPr>
         <w:p>
            <w:pPr>
               <w:tabs>
                  <w:tab w:val="left" w:pos="1047"/>
               </w:tabs>
               <w:bidi/>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
                  <w:rtl/>
               </w:rPr>
            </w:pPr>
            <w:r>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:noProof/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
                  <w:rtl/>
                  <w:lang w:val="en-GB" w:eastAsia="en-GB"/>
               </w:rPr>
               <mc:AlternateContent>
                  <mc:Choice Requires="wps">
                     <w:drawing>
                        <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="false" relativeHeight="251663360" behindDoc="false" locked="false" layoutInCell="false" allowOverlap="true" wp14:anchorId="7C8D7BB9" wp14:editId="5AD06689">
                           <wp:simplePos x="0" y="0"/>
                           <wp:positionH relativeFrom="page">
                              <wp:posOffset>169545</wp:posOffset>
                           </wp:positionH>
                           <wp:positionV relativeFrom="page">
                              <wp:posOffset>58420</wp:posOffset>
                           </wp:positionV>
                           <wp:extent cx="127000" cy="127000"/>
                           <wp:effectExtent l="0" t="0" r="6350" b="6350"/>
                           <wp:wrapNone/>
                           <wp:docPr id="4" name="Rectangle 4" xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart"/>
                           <wp:cNvGraphicFramePr xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
                              <a:graphicFrameLocks/>
                           </wp:cNvGraphicFramePr>
                           <a:graphic xmlns:dgm1612="http://schemas.microsoft.com/office/drawing/2016/12/diagram" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:pic14="http://schemas.microsoft.com/office/drawing/2010/picture" xmlns:dgm14="http://schemas.microsoft.com/office/drawing/2010/diagram" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
                              <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                 <wps:wsp xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                    <wps:cNvSpPr>
                                       <a:spLocks noChangeArrowheads="true"/>
                                    </wps:cNvSpPr>
                                    <wps:spPr bwMode="auto">
                                       <a:xfrm>
                                          <a:off x="0" y="0"/>
                                          <a:ext cx="127000" cy="127000"/>
                                       </a:xfrm>
                                       <a:prstGeom prst="rect">
                                          <a:avLst/>
                                       </a:prstGeom>
                                       <a:solidFill>
                                          <a:srgbClr val="41459E"/>
                                       </a:solidFill>
                                       <a:ln>
                                          <a:noFill/>
                                       </a:ln>
                                       <a:extLst>
                                          <a:ext uri="{91240B29-F687-4F45-9708-019B960494DF}">
                                             <a14:hiddenLine w="0">
                                                <a:solidFill>
                                                   <a:srgbClr val="000000"/>
                                                </a:solidFill>
                                                <a:miter lim="800000"/>
                                                <a:headEnd/>
                                                <a:tailEnd/>
                                             </a14:hiddenLine>
                                          </a:ext>
                                       </a:extLst>
                                    </wps:spPr>
                                    <wps:bodyPr rot="0" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" anchor="t" anchorCtr="false" upright="true">
                                       <a:noAutofit/>
                                    </wps:bodyPr>
                                 </wps:wsp>
                              </a:graphicData>
                           </a:graphic>
                           <wp14:sizeRelH relativeFrom="page">
                              <wp14:pctWidth>0</wp14:pctWidth>
                           </wp14:sizeRelH>
                           <wp14:sizeRelV relativeFrom="page">
                              <wp14:pctHeight>0</wp14:pctHeight>
                           </wp14:sizeRelV>
                        </wp:anchor>
                     </w:drawing>
                  </mc:Choice>
                  <mc:Fallback>
                     <w:pict>
                        <v:rect style="position:absolute;margin-left:13.35pt;margin-top:4.6pt;width:10pt;height:10pt;z-index:251663360;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:page;mso-position-vertical:absolute;mso-position-vertical-relative:page;mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;mso-height-relative:page;v-text-anchor:top" id="Rectangle 4" o:spid="_x0000_s1026" o:allowincell="f" stroked="f" strokeweight="0" fillcolor="#41459e" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:xvml="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:pvml="urn:schemas-microsoft-com:office:powerpoint">
                           <w10:wrap anchorx="page" anchory="page"/>
                        </v:rect>
                     </w:pict>
                  </mc:Fallback>
               </mc:AlternateContent>
            </w:r>
         </w:p>
      </w:tc>
      <w:tc>
         <w:tcPr>
            <w:tcW w:w="6654" w:type="dxa"/>
            <w:vAlign w:val="center"/>
         </w:tcPr>
         <w:p>
            <w:pPr>
               <w:tabs>
                  <w:tab w:val="left" w:pos="1047"/>
               </w:tabs>
               <w:bidi/>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
                  <w:rtl/>
               </w:rPr>
            </w:pPr>
            <w:r>
               <w:rPr>
                  <w:rFonts w:ascii="Bahij TheSansArabic Bold" w:hAnsi="Bahij TheSansArabic Bold" w:cs="Bahij TheSansArabic Bold"/>
                  <w:sz w:val="28"/>
                  <w:szCs w:val="28"/>
               </w:rPr>
               <w:t>text 2</w:t>
            </w:r>
         </w:p>
      </w:tc>
   </w:tr>
</w:tbl>



do you think since I am deep coping parts it will copy the same id wich will result in having the unreadable content? if true how can I make a new part with the formating of the template part?

Re: unreadable content whenever there is table modification

PostPosted: Thu Jul 22, 2021 7:45 am
by jason
Yes, you need to ensure your wp:docPr/@id are unique

Re: unreadable content whenever there is table modification

PostPosted: Thu Jul 22, 2021 4:27 pm
by 12AM
How to do that while keeping the format of text/cell/table ...etc?

Re: unreadable content whenever there is table modification

PostPosted: Mon Jul 26, 2021 7:24 am
by jason
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
 private static void setRandomIdsForDocPr(final MainDocumentPart document)
              throws JAXBException, XPathBinderAssociationIsPartialException
          {
            final String xpath = "//wp:docPr";
            final List<Object> docPr = document.getJAXBNodesViaXPath(xpath, false);

            for (int i = 0; i < docPr.size(); i++)
            {
              final CTNonVisualDrawingProps props = (CTNonVisualDrawingProps) docPr.get(i);
              props.setId(getNextValue());
            }
          }
     

 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


You'll need to write a getNextValue() method; it needs to return unique values.

Re: unreadable content whenever there is table modification

PostPosted: Mon Jul 26, 2021 7:45 pm
by 12AM
That fixed the issue!! thank you so much
however I thought another problem will be fixed automatically after this. after opening a document the word will freeze or have slowness as it is trying to "read" the whole document.
at the start the pages number and word count is wrong then it would increase with time.
tried to change paragraph ids in the document (anywhere that I have done a deep copy into) to see if it would fix the issue but with no luck.

Re: unreadable content whenever there is table modification

PostPosted: Tue Jul 27, 2021 6:53 am
by jason
That sounds like usual Word behaviour. How long is your document? What version of Word?

Maybe adding w:lastRenderedPageBreak elements would give it an initial page count. The number of pages (and words) is also stored in one of the metadata parts, so you could try setting that.

Re: unreadable content whenever there is table modification

PostPosted: Tue Jul 27, 2021 5:06 pm
by 12AM
more than 5 min, it will sometimes crash if you tried to scroll to other pages.
word version 2016 (16.0.14131.20326).
thank you will try both approaches.

Re: unreadable content whenever there is table modification

PostPosted: Wed Jul 28, 2021 7:48 am
by jason
And if you save in Word and re-open, it takes a lot less time? If so, perhaps Word is "correcting" other issues it identifies... you could compare the before and after XML to see how extensively it has been corrected.

When I said how long, I meant how many pages / how complex is it?

Re: unreadable content whenever there is table modification

PostPosted: Thu Jul 29, 2021 12:09 am
by 12AM
tried to save it and re-open it, takes the same time and crashes if you try to click on anything.
the resulted document will have over 100 pages and has all word's elements (tables, charts, bookmarks, hyperlinks, images, costume TOC, instructions).

I noticed that it will always delete the first chart saying "word fixed some errors by repairing Drawn Objects 1" (before upgrading to the last version it was working).
fyi, even if I have around 15 pages there is some lag while you scroll down, that is why I am thinking it could be an issue on the dynamic table addition (add multiple rows each may contain huge paragraphs) or charts.
maybe splitting some rows to have another table will fix the issue, so I have tried to add an empty paragraph after every specific block of rows, but it will always add the paragraph after the initial working table even when I added to the index of table in the document by one.

Re: unreadable content whenever there is table modification

PostPosted: Thu Jul 29, 2021 7:19 am
by jason
OK, you should figure out the issue with Drawn Objects 1. Perhaps compare the working XML to the now broken XML.

But regarding the still-slow-after-save-and-reopen, this suggests one of 2 things:
1. the document is genuinely complex (at least relative to the RAM/CPU of the computer you are opening it on), or
2. you are inadvertently approaching some Word limits in your document (eg limit on number of styles or numberings supported)

You can quickly satisfy yourself that (2) is not the case by inspecting the numbering and styles parts. (Are the 10's of entries, or 100's or 1000's?)

Regarding (1), you could try opening it on other computers or in other versions of Word or LibreOffice to see what happens. What happens in Word Online?

Do you have a single table which is pages long? First try splitting it in Word into multiple tables (there is a command which does this). That should help. If it works, then you could do the same in docx4j...

Re: unreadable content whenever there is table modification

PostPosted: Thu Jul 29, 2021 4:28 pm
by 12AM
thank you for those information! will try to fix it by splitting the tables