Hi,
I am generating XML code for my document and after generating input code I am clicking on the node to look at the respective java code.
But when I am using generated java code then output formatting is different than input applied. I have attached input and output documents.
Following is the code which got generated from online webapp.
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
// Generated code starts
org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
Document document = wmlObjectFactory.createDocument();
// Create object for body
Body body = wmlObjectFactory.createBody();
document.setBody(body);
// Create object for sectPr
SectPr sectpr = wmlObjectFactory.createSectPr();
body.setSectPr(sectpr);
// Create object for pgSz
SectPr.PgSz sectprpgsz = wmlObjectFactory.createSectPrPgSz();
sectpr.setPgSz(sectprpgsz);
sectprpgsz.setCode( BigInteger.valueOf( 9) );
sectprpgsz.setH( BigInteger.valueOf( 16838) );
sectprpgsz.setW( BigInteger.valueOf( 11906) );
// Create object for pgMar
SectPr.PgMar sectprpgmar = wmlObjectFactory.createSectPrPgMar();
sectpr.setPgMar(sectprpgmar);
sectprpgmar.setFooter( BigInteger.valueOf( 567) );
sectprpgmar.setLeft( BigInteger.valueOf( 1021) );
sectprpgmar.setRight( BigInteger.valueOf( 1021) );
sectprpgmar.setTop( BigInteger.valueOf( 1474) );
sectprpgmar.setBottom( BigInteger.valueOf( 1474) );
sectprpgmar.setGutter( BigInteger.valueOf( 0) );
sectprpgmar.setHeader( BigInteger.valueOf( 567) );
// Create object for headerReference
HeaderReference headerreference = wmlObjectFactory.createHeaderReference();
sectpr.getEGHdrFtrReferences().add( headerreference);
headerreference.setType(org.docx4j.wml.HdrFtrRef.DEFAULT);
headerreference.setId( "rId10");
// Create object for footerReference
FooterReference footerreference = wmlObjectFactory.createFooterReference();
sectpr.getEGHdrFtrReferences().add( footerreference);
footerreference.setType(org.docx4j.wml.HdrFtrRef.EVEN);
footerreference.setId( "rId11");
// Create object for footerReference
FooterReference footerreference2 = wmlObjectFactory.createFooterReference();
sectpr.getEGHdrFtrReferences().add( footerreference2);
footerreference2.setType(org.docx4j.wml.HdrFtrRef.DEFAULT);
footerreference2.setId( "rId12");
// Create object for cols
CTColumns columns = wmlObjectFactory.createCTColumns();
sectpr.setCols(columns);
columns.setSpace( BigInteger.valueOf( 708) );
// Create object for docGrid
CTDocGrid docgrid = wmlObjectFactory.createCTDocGrid();
sectpr.setDocGrid(docgrid);
docgrid.setLinePitch( BigInteger.valueOf( 360) );
// Create object for p
P p = wmlObjectFactory.createP();
body.getContent().add( p);
// Create object for pPr
PPr ppr = wmlObjectFactory.createPPr();
p.setPPr(ppr);
// Create object for rPr
ParaRPr pararpr = wmlObjectFactory.createParaRPr();
ppr.setRPr(pararpr);
// Create object for sz
HpsMeasure hpsmeasure = wmlObjectFactory.createHpsMeasure();
pararpr.setSz(hpsmeasure);
hpsmeasure.setVal( BigInteger.valueOf( 32) );
// Create object for szCs
HpsMeasure hpsmeasure2 = wmlObjectFactory.createHpsMeasure();
pararpr.setSzCs(hpsmeasure2);
hpsmeasure2.setVal( BigInteger.valueOf( 32) );
// Create object for rFonts
RFonts rfonts = wmlObjectFactory.createRFonts();
pararpr.setRFonts(rfonts);
rfonts.setAscii( "Georgia");
rfonts.setCs( "Arial");
rfonts.setHAnsi( "Georgia");
// Create object for b
BooleanDefaultTrue booleandefaulttrue = wmlObjectFactory.createBooleanDefaultTrue();
pararpr.setB(booleandefaulttrue);
// Create object for spacing
PPrBase.Spacing pprbasespacing = wmlObjectFactory.createPPrBaseSpacing();
ppr.setSpacing(pprbasespacing);
pprbasespacing.setLine( BigInteger.valueOf( 240) );
pprbasespacing.setLineRule(org.docx4j.wml.STLineSpacingRule.AUTO);
// Create object for p
P p2 = wmlObjectFactory.createP();
body.getContent().add( p2);
// Create object for tbl (wrapped in JAXBElement)
Tbl tbl = wmlObjectFactory.createTbl();
JAXBElement<org.docx4j.wml.Tbl> tblWrapped = wmlObjectFactory.createBodyTbl(tbl);
body.getContent().add( tblWrapped);
// Create object for tblPr
TblPr tblpr = wmlObjectFactory.createTblPr();
tbl.setTblPr(tblpr);
// Create object for tblW
TblWidth tblwidth = wmlObjectFactory.createTblWidth();
tblpr.setTblW(tblwidth);
tblwidth.setType( "auto");
tblwidth.setW( BigInteger.valueOf( 0) );
// Create object for tblInd
TblWidth tblwidth2 = wmlObjectFactory.createTblWidth();
tblpr.setTblInd(tblwidth2);
tblwidth2.setType( "dxa");
tblwidth2.setW( BigInteger.valueOf( -72) );
// Create object for tblBorders
TblBorders tblborders = wmlObjectFactory.createTblBorders();
tblpr.setTblBorders(tblborders);
// Create object for left
CTBorder border = wmlObjectFactory.createCTBorder();
tblborders.setLeft(border);
border.setSz( BigInteger.valueOf( 4) );
border.setVal(org.docx4j.wml.STBorder.SINGLE);
border.setColor( "auto");
border.setSpace( BigInteger.valueOf( 0) );
// Create object for right
CTBorder border2 = wmlObjectFactory.createCTBorder();
tblborders.setRight(border2);
border2.setSz( BigInteger.valueOf( 4) );
border2.setVal(org.docx4j.wml.STBorder.SINGLE);
border2.setColor( "auto");
border2.setSpace( BigInteger.valueOf( 0) );
// Create object for top
CTBorder border3 = wmlObjectFactory.createCTBorder();
tblborders.setTop(border3);
border3.setSz( BigInteger.valueOf( 4) );
border3.setVal(org.docx4j.wml.STBorder.SINGLE);
border3.setColor( "auto");
border3.setSpace( BigInteger.valueOf( 0) );
// Create object for bottom
CTBorder border4 = wmlObjectFactory.createCTBorder();
tblborders.setBottom(border4);
border4.setSz( BigInteger.valueOf( 4) );
border4.setVal(org.docx4j.wml.STBorder.SINGLE);
border4.setColor( "auto");
border4.setSpace( BigInteger.valueOf( 0) );
// Create object for insideH
CTBorder border5 = wmlObjectFactory.createCTBorder();
tblborders.setInsideH(border5);
border5.setSz( BigInteger.valueOf( 4) );
border5.setVal(org.docx4j.wml.STBorder.SINGLE);
border5.setColor( "auto");
border5.setSpace( BigInteger.valueOf( 0) );
// Create object for insideV
CTBorder border6 = wmlObjectFactory.createCTBorder();
tblborders.setInsideV(border6);
border6.setSz( BigInteger.valueOf( 4) );
border6.setVal(org.docx4j.wml.STBorder.SINGLE);
border6.setColor( "auto");
border6.setSpace( BigInteger.valueOf( 0) );
// Create object for tblCellMar
CTTblCellMar tblcellmar = wmlObjectFactory.createCTTblCellMar();
tblpr.setTblCellMar(tblcellmar);
// Create object for top
TblWidth tblwidth3 = wmlObjectFactory.createTblWidth();
tblcellmar.setTop(tblwidth3);
tblwidth3.setType( "dxa");
tblwidth3.setW( BigInteger.valueOf( 28) );
// Create object for bottom
TblWidth tblwidth4 = wmlObjectFactory.createTblWidth();
tblcellmar.setBottom(tblwidth4);
tblwidth4.setType( "dxa");
tblwidth4.setW( BigInteger.valueOf( 28) );
// Create object for tblLook
CTTblLook tbllook = wmlObjectFactory.createCTTblLook();
tblpr.setTblLook(tbllook);
tbllook.setVal( "0000");
tbllook.setNoVBand(org.docx4j.sharedtypes.STOnOff.ZERO);
tbllook.setFirstRow(org.docx4j.sharedtypes.STOnOff.ZERO);
tbllook.setLastRow(org.docx4j.sharedtypes.STOnOff.ZERO);
tbllook.setFirstColumn(org.docx4j.sharedtypes.STOnOff.ZERO);
tbllook.setLastColumn(org.docx4j.sharedtypes.STOnOff.ZERO);
tbllook.setNoHBand(org.docx4j.sharedtypes.STOnOff.ZERO);
// Create object for tblGrid
TblGrid tblgrid = wmlObjectFactory.createTblGrid();
tbl.setTblGrid(tblgrid);
// Create object for gridCol
TblGridCol tblgridcol = wmlObjectFactory.createTblGridCol();
tblgrid.getGridCol().add( tblgridcol);
tblgridcol.setW( BigInteger.valueOf( 9536) );
// Create object for tr
Tr tr = wmlObjectFactory.createTr();
tbl.getContent().add( tr);
// Create object for trPr
TrPr trpr = wmlObjectFactory.createTrPr();
tr.setTrPr(trpr);
// Create object for trHeight (wrapped in JAXBElement)
CTHeight height = wmlObjectFactory.createCTHeight();
JAXBElement<org.docx4j.wml.CTHeight> heightWrapped = wmlObjectFactory.createCTTrPrBaseTrHeight(height);
trpr.getCnfStyleOrDivIdOrGridBefore().add( heightWrapped);
height.setVal( BigInteger.valueOf( 386) );
// Create object for tblHeader (wrapped in JAXBElement)
BooleanDefaultTrue booleandefaulttrue2 = wmlObjectFactory.createBooleanDefaultTrue();
JAXBElement<org.docx4j.wml.BooleanDefaultTrue> booleandefaulttrueWrapped = wmlObjectFactory.createCTTrPrBaseTblHeader(booleandefaulttrue2);
trpr.getCnfStyleOrDivIdOrGridBefore().add( booleandefaulttrueWrapped);
// Create object for tc (wrapped in JAXBElement)
Tc tc = wmlObjectFactory.createTc();
JAXBElement<org.docx4j.wml.Tc> tcWrapped = wmlObjectFactory.createTrTc(tc);
tr.getContent().add( tcWrapped);
// Create object for tcPr
TcPr tcpr = wmlObjectFactory.createTcPr();
tc.setTcPr(tcpr);
// Create object for shd
CTShd shd = wmlObjectFactory.createCTShd();
tcpr.setShd(shd);
shd.setVal(org.docx4j.wml.STShd.CLEAR);
shd.setColor( "auto");
shd.setFill( "EAEAE2");
// Create object for vAlign
CTVerticalJc verticaljc = wmlObjectFactory.createCTVerticalJc();
tcpr.setVAlign(verticaljc);
verticaljc.setVal(org.docx4j.wml.STVerticalJc.CENTER);
// Create object for tcW
TblWidth tblwidth5 = wmlObjectFactory.createTblWidth();
tcpr.setTcW(tblwidth5);
tblwidth5.setType( "dxa");
tblwidth5.setW( BigInteger.valueOf( 9536) );
// Create object for p
P p3 = wmlObjectFactory.createP();
tc.getContent().add( p3);
// Create object for pPr
PPr ppr2 = wmlObjectFactory.createPPr();
p3.setPPr(ppr2);
// Create object for rPr
ParaRPr pararpr2 = wmlObjectFactory.createParaRPr();
ppr2.setRPr(pararpr2);
// Create object for bCs
BooleanDefaultTrue booleandefaulttrue3 = wmlObjectFactory.createBooleanDefaultTrue();
pararpr2.setBCs(booleandefaulttrue3);
// Create object for b
BooleanDefaultTrue booleandefaulttrue4 = wmlObjectFactory.createBooleanDefaultTrue();
pararpr2.setB(booleandefaulttrue4);
// Create object for spacing
PPrBase.Spacing pprbasespacing2 = wmlObjectFactory.createPPrBaseSpacing();
ppr2.setSpacing(pprbasespacing2);
pprbasespacing2.setAfter( BigInteger.valueOf( 0) );
pprbasespacing2.setLine( BigInteger.valueOf( 240) );
pprbasespacing2.setLineRule(org.docx4j.wml.STLineSpacingRule.AUTO);
pprbasespacing2.setBefore( BigInteger.valueOf( 0) );
// Create object for pStyle
PPrBase.PStyle pprbasepstyle = wmlObjectFactory.createPPrBasePStyle();
ppr2.setPStyle(pprbasepstyle);
pprbasepstyle.setVal( "TableColumnHeader");
// Create object for r
R r = wmlObjectFactory.createR();
p3.getContent().add( r);
// Create object for rPr
RPr rpr = wmlObjectFactory.createRPr();
r.setRPr(rpr);
// Create object for rFonts
RFonts rfonts2 = wmlObjectFactory.createRFonts();
rpr.setRFonts(rfonts2);
rfonts2.setCs( "Arial");
// Create object for bCs
BooleanDefaultTrue booleandefaulttrue5 = wmlObjectFactory.createBooleanDefaultTrue();
rpr.setBCs(booleandefaulttrue5);
// Create object for b
BooleanDefaultTrue booleandefaulttrue6 = wmlObjectFactory.createBooleanDefaultTrue();
rpr.setB(booleandefaulttrue6);
// Create object for t (wrapped in JAXBElement)
Text text = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
r.getContent().add( textWrapped);
text.setValue( "Some Title");
// Create object for bookmarkStart (wrapped in JAXBElement)
CTBookmark bookmark = wmlObjectFactory.createCTBookmark();
JAXBElement<org.docx4j.wml.CTBookmark> bookmarkWrapped = wmlObjectFactory.createPBookmarkStart(bookmark);
p3.getContent().add( bookmarkWrapped);
bookmark.setName( "_GoBack");
bookmark.setId( BigInteger.valueOf( 0) );
// Create object for bookmarkEnd (wrapped in JAXBElement)
CTMarkupRange markuprange = wmlObjectFactory.createCTMarkupRange();
JAXBElement<org.docx4j.wml.CTMarkupRange> markuprangeWrapped = wmlObjectFactory.createPBookmarkEnd(markuprange);
p3.getContent().add( markuprangeWrapped);
markuprange.setId( BigInteger.valueOf( 0) );
// Create object for tr
Tr tr2 = wmlObjectFactory.createTr();
tbl.getContent().add( tr2);
// Create object for trPr
TrPr trpr2 = wmlObjectFactory.createTrPr();
tr2.setTrPr(trpr2);
// Create object for trHeight (wrapped in JAXBElement)
CTHeight height2 = wmlObjectFactory.createCTHeight();
JAXBElement<org.docx4j.wml.CTHeight> heightWrapped2 = wmlObjectFactory.createCTTrPrBaseTrHeight(height2);
trpr2.getCnfStyleOrDivIdOrGridBefore().add( heightWrapped2);
height2.setVal( BigInteger.valueOf( 427) );
// Create object for tc (wrapped in JAXBElement)
Tc tc2 = wmlObjectFactory.createTc();
JAXBElement<org.docx4j.wml.Tc> tcWrapped2 = wmlObjectFactory.createTrTc(tc2);
tr2.getContent().add( tcWrapped2);
// Create object for tcPr
TcPr tcpr2 = wmlObjectFactory.createTcPr();
tc2.setTcPr(tcpr2);
// Create object for vAlign
CTVerticalJc verticaljc2 = wmlObjectFactory.createCTVerticalJc();
tcpr2.setVAlign(verticaljc2);
verticaljc2.setVal(org.docx4j.wml.STVerticalJc.CENTER);
// Create object for tcW
TblWidth tblwidth6 = wmlObjectFactory.createTblWidth();
tcpr2.setTcW(tblwidth6);
tblwidth6.setType( "dxa");
tblwidth6.setW( BigInteger.valueOf( 9536) );
// Create object for tcBorders
TcPrInner.TcBorders tcprinnertcborders = wmlObjectFactory.createTcPrInnerTcBorders();
tcpr2.setTcBorders(tcprinnertcborders);
// Create object for bottom
CTBorder border7 = wmlObjectFactory.createCTBorder();
tcprinnertcborders.setBottom(border7);
border7.setSz( BigInteger.valueOf( 4) );
border7.setVal(org.docx4j.wml.STBorder.SINGLE);
border7.setColor( "auto");
border7.setSpace( BigInteger.valueOf( 0) );
// Create object for p
P p4 = wmlObjectFactory.createP();
tc2.getContent().add( p4);
// Create object for pPr
PPr ppr3 = wmlObjectFactory.createPPr();
p4.setPPr(ppr3);
// Create object for rPr
ParaRPr pararpr3 = wmlObjectFactory.createParaRPr();
ppr3.setRPr(pararpr3);
// Create object for sz
HpsMeasure hpsmeasure3 = wmlObjectFactory.createHpsMeasure();
pararpr3.setSz(hpsmeasure3);
hpsmeasure3.setVal( BigInteger.valueOf( 20) );
// Create object for b
BooleanDefaultTrue booleandefaulttrue7 = wmlObjectFactory.createBooleanDefaultTrue();
pararpr3.setB(booleandefaulttrue7);
// Create object for pStyle
PPrBase.PStyle pprbasepstyle2 = wmlObjectFactory.createPPrBasePStyle();
ppr3.setPStyle(pprbasepstyle2);
pprbasepstyle2.setVal( "Heading2");
// Create object for bookmarkStart (wrapped in JAXBElement)
CTBookmark bookmark2 = wmlObjectFactory.createCTBookmark();
JAXBElement<org.docx4j.wml.CTBookmark> bookmarkWrapped2 = wmlObjectFactory.createPBookmarkStart(bookmark2);
p4.getContent().add( bookmarkWrapped2);
bookmark2.setName( "Introduction1");
bookmark2.setColFirst( BigInteger.valueOf( 0) );
bookmark2.setColLast( BigInteger.valueOf( 0) );
bookmark2.setId( BigInteger.valueOf( 1) );
// Create object for r
R r2 = wmlObjectFactory.createR();
p4.getContent().add( r2);
// Create object for rPr
RPr rpr2 = wmlObjectFactory.createRPr();
r2.setRPr(rpr2);
// Create object for sz
HpsMeasure hpsmeasure4 = wmlObjectFactory.createHpsMeasure();
rpr2.setSz(hpsmeasure4);
hpsmeasure4.setVal( BigInteger.valueOf( 20) );
// Create object for b
BooleanDefaultTrue booleandefaulttrue8 = wmlObjectFactory.createBooleanDefaultTrue();
rpr2.setB(booleandefaulttrue8);
// Create object for t (wrapped in JAXBElement)
Text text2 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped2 = wmlObjectFactory.createRT(text2);
r2.getContent().add( textWrapped2);
text2.setValue( "Introduction");
// Create object for bookmarkEnd (wrapped in JAXBElement)
CTMarkupRange markuprange2 = wmlObjectFactory.createCTMarkupRange();
JAXBElement<org.docx4j.wml.CTMarkupRange> markuprangeWrapped2 = wmlObjectFactory.createTblBookmarkEnd(markuprange2);
tbl.getContent().add( markuprangeWrapped2);
markuprange2.setId( BigInteger.valueOf( 1) );
// Create object for p
P p5 = wmlObjectFactory.createP();
body.getContent().add( p5);
// Create object for p
P p6 = wmlObjectFactory.createP();
body.getContent().add( p6);
// Create object for pPr
PPr ppr4 = wmlObjectFactory.createPPr();
p6.setPPr(ppr4);
// Create object for spacing
PPrBase.Spacing pprbasespacing3 = wmlObjectFactory.createPPrBaseSpacing();
ppr4.setSpacing(pprbasespacing3);
pprbasespacing3.setLine( BigInteger.valueOf( 240) );
pprbasespacing3.setLineRule(org.docx4j.wml.STLineSpacingRule.AUTO);
document.setIgnorable( "w14 w15 wp14");
// Generated code ends
wordMLPackage.getMainDocumentPart().addObject(tbl) ;
wordMLPackage.save(new java.io.File("D://Output Doc.docx"));