Introduction

Aspose.Words FOSS for Python provides a straightforward API for converting Word documents from supported input formats to PDF, Markdown, and plain text. The Document class loads files in five input formats and the save() method exports to PDF, Markdown, or plain text.

This post walks through the core conversion workflows, from single-file conversion to batch processing across all supported formats.


Key Features

Single Document Conversion

Load any supported input file and convert it to a target format with two lines of code. The Document constructor accepts DOCX, DOC, RTF, TXT, and Markdown files.

import aspose.words_foss as aw

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

Batch Conversion to Multiple Formats

Call save() multiple times on the same loaded document to produce outputs in every supported format without reloading the input file.

import aspose.words_foss as aw

doc = aw.Document("report.docx")
doc.save("report.md", aw.SaveFormat.MARKDOWN)
doc.save("report.pdf", aw.SaveFormat.PDF)
doc.save("report.txt", aw.SaveFormat.TEXT)

PDF Export with PdfSaveOptions

Use PdfSaveOptions for fine-grained control over PDF output. For default settings, SaveFormat.PDF is sufficient.

import aspose.words_foss as aw
from aspose.words_foss.saving import PdfSaveOptions

doc = aw.Document("input.docx")
pdf_opts = PdfSaveOptions()
doc.save("output.pdf", pdf_opts)

Markdown Export with MarkdownSaveOptions

Use MarkdownSaveOptions for additional control over Markdown output formatting.

import aspose.words_foss as aw
from aspose.words_foss.saving import MarkdownSaveOptions

doc = aw.Document("input.docx")
md_opts = MarkdownSaveOptions()
doc.save("output.md", md_opts)

Text Extraction

Extract plain text content from any loaded document using Document.get_text() without writing to a file.

import aspose.words_foss as aw

doc = aw.Document("input.docx")
text = doc.get_text()
print(f"Extracted {len(text)} characters")

Quick Start

pip install aspose-words-foss>=26.4.0
import aspose.words_foss as aw

# Load a Word document
doc = aw.Document("contract.docx")

# Convert to all output formats
doc.save("contract.md", aw.SaveFormat.MARKDOWN)
doc.save("contract.pdf", aw.SaveFormat.PDF)
doc.save("contract.txt", aw.SaveFormat.TEXT)

# Extract text for processing
text = doc.get_text()
print(f"Document contains {len(text)} characters")

Supported Formats

FormatExtensionReadWrite
DOCX.docx
DOC.doc
RTF.rtf
TXT.txt
Markdown.md
PDF.pdf

Open Source & Licensing

Aspose.Words FOSS for Python is released under the MIT License. You can use it in personal, internal, and commercial projects without license fees. The source code is available on GitHub.


Getting Started