TextDocument newDoc = TextDocument.newTextDocument();
// create a new master page
Paragraph paragraph = newDoc
.addParagraph("before page break - original Landscape");
MasterPage master1 = MasterPage.getOrCreateMasterPage(newDoc,
"Landscape");
master1.setPageWidth(279.4);
master1.setPageHeight(215.9);
master1.setNumberFormat(NumberFormat.HINDU_ARABIC_NUMBER.toString());
master1.setPrintOrientation(PrintOrientation.LANDSCAPE);
master1.setFootnoteMaxHeight(0);
master1.setWritingMode(StyleTypeDefinitions.WritingMode.LRTB);
master1.setMargins(20, 20, 20, 20);
master1.setFootnoteSepProperties(AdjustmentStyle.LEFT, Color
.valueOf("#000000"), 1, 1, null, Percent.valueOf("25%"),
0.18);
newDoc.addPageBreak(paragraph, master1);
newDoc.addParagraph("after page break - original Landscape");
validMasterPageApplied(newDoc, paragraph, master1);
newDoc
.save(ResourceUtilities
.newTestOutputFile("AddPageBreakWithMasterPageOutput1.odt"));
// modify the master page
paragraph = newDoc
.addParagraph("before page break - modified Landscape");
MasterPage master2 = MasterPage.getOrCreateMasterPage(newDoc,
"Landscape");
master2.setPageWidth(100);
master2.setPageHeight(300);
master2.setNumberFormat(null);
master2.setPrintOrientation(null);
master2.setMargins(20, 20, 0, 0);
newDoc.addPageBreak(paragraph, master2);
newDoc.addParagraph("after page break - modified Landscape");
validMasterPageApplied(newDoc, paragraph, master2);
// apply existing master page
paragraph = newDoc.addParagraph("before page break - Standard");
MasterPage master3 = MasterPage.getOrCreateMasterPage(newDoc,
"Standard");
newDoc.addPageBreak(paragraph, master3);
newDoc.addParagraph("after page break - Standard");
newDoc.addParagraph("end page");
newDoc