How to Convert Documents with Converter Classes in Python

How to Convert Documents with Converter Classes in Python

How to Convert Documents with Converter Classes

Aspose.Words FOSS for Python uses internal converter classes during document export. While most users interact with Document.save(), understanding the converter classes is useful for advanced scenarios.

Prerequisites

Install the library:

pip install aspose-words-foss>=26.4.0

Requires Python 3.10 or later.

ParagraphConverter

ParagraphConverter transforms document paragraphs into the target output format. Key methods:

  • ParagraphConverter.get_paragraph_info() — extract formatting information from a paragraph
  • ParagraphConverter.get_run_formatting() — get formatting for a text run
  • ParagraphConverter.format_text() — apply formatting to text content

TableConverter

TableConverter converts document tables to the target format (such as Markdown tables):

  • TableConverter.convert() — convert a table element to the output format

ListHandler

ListHandler manages list state during conversion:

  • ListHandler.set_reader() — set the document reader context
  • ListHandler.reset() — reset list tracking state
  • ListHandler.get_list_info() — get list item details for a paragraph
  • ListHandler.format_list_item() — format a list item with marker and indentation
  • ListHandler.break_list() — signal end of a list sequence

Quick Conversion Example

For most use cases, use Document.save() directly — the converter classes are invoked automatically:

import aspose.words_foss as aw

doc = aw.Document("input.docx")
doc.save("output.pdf", aw.SaveFormat.PDF)

Summary

ConverterPurpose
ParagraphConverterTransform paragraphs with formatting
TableConverterConvert tables to output format
ListHandlerManage list state during export

See Also

 English