com.aspose.words

Class SectionStart

  • java.lang.Object
    • com.aspose.words.SectionStart
public class SectionStart 
extends java.lang.Object

Utility class containing constants. The type of break at the beginning of the section.

Example:

Shows how to construct an Aspose.Words document by hand.
Document doc = new Document();

// A blank document contains one section, one body and one paragraph.
// Call the "RemoveAllChildren" method to remove all those nodes,
// and end up with a document node with no children.
doc.removeAllChildren();

// This document now has no composite child nodes that we can add content to.
// If we wish to edit it, we will need to repopulate its node collection.
// First, create a new section, and then append it as a child to the root document node.
Section section = new Section(doc);
doc.appendChild(section);

// Set some page setup properties for the section.
section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(PaperSize.LETTER);

// A section needs a body, which will contain and display all of its contents
// on the page between the section's header and footer.
Body body = new Body(doc);
section.appendChild(body);

// Create a paragraph, set some formatting properties, and then append it as a child to the body.
Paragraph para = new Paragraph(doc);

para.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

body.appendChild(para);

// Finally, add some content to do the document by creating a run,
// setting its text contents and appearance, and appending it as a child to the paragraph.
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);

Assert.assertEquals("Hello World!", doc.getText().trim());

doc.save(getArtifactsDir() + "Section.CreateManually.docx");

Example:

Shows how to specify how a new section separates itself from the previous.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("This text is in section 1.");

// Section break types determine how a new section separates itself from the previous section.
// Below are five types of section breaks.
// 1 -  Starts the next section on a new page:
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.writeln("This text is in section 2.");

Assert.assertEquals(SectionStart.NEW_PAGE, doc.getSections().get(1).getPageSetup().getSectionStart());

// 2 -  Starts the next section on the current page:
builder.insertBreak(BreakType.SECTION_BREAK_CONTINUOUS);
builder.writeln("This text is in section 3.");

Assert.assertEquals(SectionStart.CONTINUOUS, doc.getSections().get(2).getPageSetup().getSectionStart());

// 3 -  Starts the next section on a new even page:
builder.insertBreak(BreakType.SECTION_BREAK_EVEN_PAGE);
builder.writeln("This text is in section 4.");

Assert.assertEquals(SectionStart.EVEN_PAGE, doc.getSections().get(3).getPageSetup().getSectionStart());

// 4 -  Starts the next section on a new odd page:
builder.insertBreak(BreakType.SECTION_BREAK_ODD_PAGE);
builder.writeln("This text is in section 5.");

Assert.assertEquals(SectionStart.ODD_PAGE, doc.getSections().get(4).getPageSetup().getSectionStart());

// 5 -  Starts the next section on a new column:
TextColumnCollection columns = builder.getPageSetup().getTextColumns();
columns.setCount(2);

builder.insertBreak(BreakType.SECTION_BREAK_NEW_COLUMN);
builder.writeln("This text is in section 6.");

Assert.assertEquals(SectionStart.NEW_COLUMN, doc.getSections().get(5).getPageSetup().getSectionStart());

doc.save(getArtifactsDir() + "PageSetup.SetSectionStart.docx");

Field Summary
static final intCONTINUOUS = 0
The new section starts on the same page as the previous section.
static final intNEW_COLUMN = 1
The section starts from a new column.
static final intNEW_PAGE = 2
The section starts from a new page.
static final intEVEN_PAGE = 3
The section starts on a new even page.
static final intODD_PAGE = 4
The section starts on a new odd page.
 

    • Field Detail

      • CONTINUOUS = 0

        public static final int CONTINUOUS
        The new section starts on the same page as the previous section.
      • NEW_COLUMN = 1

        public static final int NEW_COLUMN
        The section starts from a new column.
      • NEW_PAGE = 2

        public static final int NEW_PAGE
        The section starts from a new page.
      • EVEN_PAGE = 3

        public static final int EVEN_PAGE
        The section starts on a new even page.
      • ODD_PAGE = 4

        public static final int ODD_PAGE
        The section starts on a new odd page.