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.0Requires 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 paragraphParagraphConverter.get_run_formatting()— get formatting for a text runParagraphConverter.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 contextListHandler.reset()— reset list tracking stateListHandler.get_list_info()— get list item details for a paragraphListHandler.format_list_item()— format a list item with marker and indentationListHandler.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
| Converter | Purpose |
|---|---|
ParagraphConverter | Transform paragraphs with formatting |
TableConverter | Convert tables to output format |
ListHandler | Manage list state during export |