Page 1 of 1

Inserting Page Break in docx file through docx4j

PostPosted: Wed Sep 22, 2010 9:59 pm
by goldburg12345
hi All,
i am trying to create a docx file through docx4j tool and need to add page break in the document.
Can any one help in doing so?
i am trying following code but it doesn't seem to work.
P para = factory.createP();
R run = factory.createR();
run.setParent(new R.LastRenderedPageBreak().getParent());
para.getParagraphContent().add(run);
body.getEGBlockLevelElts().add(para);


Thanks for help.
Bhavin

Re: Inserting Page Break in docx file through docx4j

PostPosted: Thu Sep 23, 2010 12:55 am
by goldburg12345
I manage to find solution for myself n thought may be useful to others so posting here.

Br objBr = new Br();
objBr.setType(STBrType.PAGE);
P para = factory.createP();
para.getParagraphContent().add(objBr);


Try above code and then simply add that para object to the body object of main document.

hope its helpful.