Documents can be broken into sections using the getSections property of the Document class. Breaking a document into sections has several benefits:
- You can use the section numbering options of the Page Numbering Label Page Element.
- You can use section templates to apply Page Elements to all pages in a section.
- You can control the page labels that are displayed in a PDF viewer.
Each section can have a numbering style specified. See the NumberingStyle enumeration for a list of supported numbering styles. If no numbering style is specified, numeric numbering is used. The section's numbering style affects the page's label in Acrobat and is the default numbering style used by the page numbering label page element.
The following example shows how to break a document into sections.
[Java]
Document document = new Document();
//Create a template object and add a page numbering label
Template template = new Template();
template.getElements().add(new PageNumberingLabel("%%SP%% of %%ST%%", 0, 680, 512,
12, Font.getHelvetica(), 12, TextAlign.CENTER));
//Begin the first section
document.getSections().begin(NumberingStyle.ROMAN_LOWERCASE);
//Add two pages
document.getPages().add(new Page()); //Page 1
document.getPages().add(new Page()); //Page 2
//Begin the second section
document.getSections().begin(NumberingStyle.NUMERIC, template);
//Add three pages
document.getPages().add(new Page()); //Page 3
document.getPages().add(new Page()); //page 4
document.getPages().add(new Page()); //page 5
//Begin the third section specifying a section prefix
document.getSections().begin(NumberingStyle.ROMAN_LOWERCASE, "Appendix A - ");
//Add two pages
document.getPages().add(new Page()); //page 6
document.getPages().add(new Page()); //page 7
//Save the PDF
document.draw("[PhysicalPath]/MyDocument.pdf");