export_toc_page_numbers property

HtmlSaveOptions.export_toc_page_numbers property

Specifies whether to write page numbers to table of contents when saving HTML, MHTML and EPUB. Default value is False.

@property
def export_toc_page_numbers(self) -> bool:
    ...

@export_toc_page_numbers.setter
def export_toc_page_numbers(self, value: bool):
    ...

Examples

Shows how to display page numbers when saving a document with a table of contents to .html.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# Insert a table of contents, and then populate the document with paragraphs formatted using a "Heading"
# style that the table of contents will pick up as entries. Each entry will display the heading paragraph on the left,
# and the page number that contains the heading on the right.
field_toc = builder.insert_field(field_type=aw.fields.FieldType.FIELD_TOC, update_field=True).as_field_toc()
builder.paragraph_format.style = builder.document.styles.get_by_name('Heading 1')
builder.insert_break(aw.BreakType.PAGE_BREAK)
builder.writeln('Entry 1')
builder.writeln('Entry 2')
builder.insert_break(aw.BreakType.PAGE_BREAK)
builder.writeln('Entry 3')
builder.insert_break(aw.BreakType.PAGE_BREAK)
builder.writeln('Entry 4')
field_toc.update_page_numbers()
doc.update_fields()
# HTML documents do not have pages. If we save this document to HTML,
# the page numbers that our TOC displays will have no meaning.
# When we save the document to HTML, we can pass a SaveOptions object to omit these page numbers from the TOC.
# If we set the "ExportTocPageNumbers" flag to "true",
# each TOC entry will display the heading, separator, and page number, preserving its appearance in Microsoft Word.
# If we set the "ExportTocPageNumbers" flag to "false",
# the save operation will omit both the separator and page number and leave the heading for each entry intact.
options = aw.saving.HtmlSaveOptions()
options.export_toc_page_numbers = export_toc_page_numbers
doc.save(file_name=ARTIFACTS_DIR + 'HtmlSaveOptions.ExportTocPageNumbers.html', save_options=options)
out_doc_contents = system_helper.io.File.read_all_text(ARTIFACTS_DIR + 'HtmlSaveOptions.ExportTocPageNumbers.html')
if export_toc_page_numbers:
    self.assertTrue('<span>Entry 1</span>' + '<span style="width:428.14pt; font-family:\'Lucida Console\'; font-size:10pt; display:inline-block; -aw-font-family:\'Times New Roman\'; ' + '-aw-tabstop-align:right; -aw-tabstop-leader:dots; -aw-tabstop-pos:469.8pt">.......................................................................</span>' + '<span>2</span>' + '</p>' in out_doc_contents)
else:
    self.assertTrue('<p style="margin-top:0pt; margin-bottom:0pt">' + '<span>Entry 2</span>' + '</p>' in out_doc_contents)

See Also