Document Sectioning
Break documents into sections using the Sections property of the Document class. Breaking a document into sections has several benefits.
- Allows using the section numbering options of the Page Numbering Label Page Element.
- Allows using section templates to apply Page Elements to all sections in a page.
- Allows controlling the page labels that are displayed in a PDF viewer.
Sections
A Document has a Sections property. The Sections property is a SectionsList containing the sections. 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.
Document document = new Document();
// Create a template object and add a page numbering label
Template template = new Template();
template.Elements.Add( new PageNumberingLabel( "%%SP%% of %%ST%%", 0, 680, 512, 12, Font.Helvetica, 12, TextAlign.Center ) );
// Begin the first section
document.Sections.Begin( NumberingStyle.RomanLowerCase );
// Add two pages
document.Pages.Add( new Page() ); //Page 1
document.Pages.Add( new Page() ); //Page 2
// Begin the second section
document.Sections.Begin( NumberingStyle.Numeric, template );
// Add three pages
document.Pages.Add( new Page() ); //Page 3
document.Pages.Add( new Page() ); //page 4
document.Pages.Add( new Page() ); //page 5
// Begin the third section specifying a section prefix
document.Sections.Begin( NumberingStyle.RomanLowerCase, "Appendix A - " );
// Add two pages
document.Pages.Add( new Page() ); //page 6
document.Pages.Add( new Page() ); //page 7
// Save the PDF
document.Draw(pdfFilePath);
Dim MyDocument As Document = New Document()
' Create a template object and add a page numbering label
Dim MyTemplate As Template = New Template()
MyTemplate.Elements.Add( New PageNumberingLabel( "%%SP%% of %%ST%%", 0, 680, 512, 12, Font.Helvetica, 12, TextAlign.Center ) )
' Begin the first section
MyDocument.Sections.Begin( NumberingStyle.RomanLowerCase )
' Add two pages
MyDocument.Pages.Add( new Page() ) 'Page 1
MyDocument.Pages.Add( new Page() ) 'Page 2
' Begin the second section
MyDocument.Sections.Begin( NumberingStyle.Numeric, MyTemplate )
' Add three pages
MyDocument.Pages.Add( new Page() ) 'Page 3
MyDocument.Pages.Add( new Page() ) 'page 4
MyDocument.Pages.Add( new Page() ) 'page 5
' Begin the third section specifying a section prefix
MyDocument.Sections.Begin( NumberingStyle.RomanLowerCase, "Appendix A - " )
' Add two pages
MyDocument.Pages.Add( new Page() ) 'page 6
MyDocument.Pages.Add( new Page() ) 'page 7
' Save the PDF
MyDocument.Draw(pdfFilePath)
Refer to the SectionsList and Sections property API documentation for complete examples.