Section
paper-docx 0.2.0 API reference
Document section, providing access to section and page setup settings.
Also provides access to headers and footers.
Section(sectPr: CT_SectPr, document_part: DocumentPart)Attributes
bottom_margin
attributebottom_marginLength | NoneRead/write. Bottom margin for pages in this section, in EMU.
None when no bottom margin has been specified. Assigning None removes any
bottom-margin setting.
different_first_page_header_footer
attributedifferent_first_page_header_footerboolTrue if this section displays a distinct first-page header and footer.
Read/write. The definition of the first-page header and footer are accessed
using :attr:.first_page_header and :attr:.first_page_footer respectively.
even_page_footer
attributeeven_page_footer_Footer_Footer object defining footer content for even pages.
The content of this footer definition is ignored unless the document setting
:attr:~.Settings.odd_and_even_pages_header_footer is set True.
even_page_header
attributeeven_page_header_Header_Header object defining header content for even pages.
The content of this header definition is ignored unless the document setting
:attr:~.Settings.odd_and_even_pages_header_footer is set True.
first_page_footer
attributefirst_page_footer_Footer_Footer object defining footer content for the first page of this section.
The content of this footer definition is ignored unless the property
:attr:.different_first_page_header_footer is set True.
first_page_header
attributefirst_page_header_Header_Header object defining header content for the first page of this section.
The content of this header definition is ignored unless the property
:attr:.different_first_page_header_footer is set True.
footer
attributefooter_Footer_Footer object representing default page footer for this section.
The default footer is used for odd-numbered pages when separate odd/even footers are enabled. It is used for both odd and even-numbered pages otherwise.
footer_distance
attributefooter_distanceLength | NoneDistance from bottom edge of page to bottom edge of the footer.
Read/write. None if no setting is present in the XML.
gutter
attributegutterLength | NoneLength object representing page gutter size in English Metric Units.
Read/write. The page gutter is extra spacing added to the inner margin to
ensure even margins after page binding. Generally only used in book-bound
documents with double-sided and facing pages.
This setting applies to all pages in this section.
header
attributeheader_Header_Header object representing default page header for this section.
The default header is used for odd-numbered pages when separate odd/even headers are enabled. It is used for both odd and even-numbered pages otherwise.
header_distance
attributeheader_distanceLength | NoneDistance from top edge of page to top edge of header.
Read/write. None if no setting is present in the XML. Assigning None causes
default value to be used.
left_margin
attributeleft_marginLength | NoneLength object representing the left margin for all pages in this section in
English Metric Units.
orientation
attributeorientationWD_ORIENTATION:ref:WdOrientation member specifying page orientation for this section.
One of WD_ORIENT.PORTRAIT or WD_ORIENT.LANDSCAPE.
page_height
attributepage_heightLength | NoneTotal page height used for this section.
This value is inclusive of all edge spacing values such as margins.
Page orientation is taken into account, so for example, its expected value
would be Inches(8.5) for letter-sized paper when orientation is landscape.
page_width
attributepage_widthLength | NoneTotal page width used for this section.
This value is like "paper size" and includes all edge spacing values such as margins.
Page orientation is taken into account, so for example, its expected value
would be Inches(11) for letter-sized paper when orientation is landscape.
part
attributepartStoryPartright_margin
attributeright_marginLength | NoneLength object representing the right margin for all pages in this section
in English Metric Units.
start_type
attributestart_typeWD_SECTION_STARTType of page-break (if any) inserted at the start of this section.
For exmple, WD_SECTION_START.ODD_PAGE if the section should begin on the
next odd page, possibly inserting two page-breaks instead of one.
top_margin
attributetop_marginLength | NoneLength object representing the top margin for all pages in this section in
English Metric Units.
Functions
iter_inner_content
funciter_inner_content() -> Iterator[Paragraph | Table]Generate each Paragraph or Table object in this section.
Items appear in document order.
Returns
typing.Iterator[docx.text.paragraph.Paragraph | docx.table.Table]