Introduction
Aspose.Words FOSS is an open-source Python library for working with Word documents. It reads DOCX, DOC, RTF, TXT, and Markdown files, and can export them to PDF, Markdown, or plain text — all without requiring Microsoft Word or any native dependencies.
The library is released under the MIT License and is available on PyPI. Install it with:
pip install aspose-words-fossAspose.Words FOSS requires Python 3.10 or later and depends on three pure-Python packages (olefile, fpdf2, pydantic), installed automatically by pip.
Key Features
Document Loading and Conversion
The Document class is the primary entry point. Load a file in any supported input format, then use a dedicated Writer class (LdmDocxWriter, LdmMarkdownWriter, LdmPdfWriter) to convert it to a different output format.
import aspose.words_foss as aw
from aspose.words_foss.md_writer import LdmMarkdownWriter
doc = aw.Document("input.docx") # or .doc, .rtf, .txt, .md
LdmMarkdownWriter().write(doc, "output.md")
PDF Export
Export Word documents to PDF using LdmPdfWriter, passing a PdfSaveOptions instance for fine-grained control.
import aspose.words_foss as aw
from aspose.words_foss.pdf_writer import LdmPdfWriter
doc = aw.Document("input.docx")
LdmPdfWriter().write(doc, "output.pdf")
Markdown Export with Save Options
Pass a MarkdownSaveOptions or PdfSaveOptions instance to the writer’s constructor for fine-grained control over output formatting.
import aspose.words_foss as aw
from aspose.words_foss.md_writer import LdmMarkdownWriter
from aspose.words_foss.pdf_writer import LdmPdfWriter
from aspose.words_foss.saving import MarkdownSaveOptions, PdfSaveOptions
doc = aw.Document("input.docx")
md_opts = MarkdownSaveOptions()
LdmMarkdownWriter(md_opts).write(doc, "output.md")
pdf_opts = PdfSaveOptions()
LdmPdfWriter(pdf_opts).write(doc, "output.pdf")
Text Extraction
Extract plain text from any supported document format using the Document.text property.
import aspose.words_foss as aw
doc = aw.Document("input.docx")
text = doc.text
Document Structure Parsing
Specialized parsers extract structured data from DOCX internals. NumberingParser reads list numbering definitions and StyleParser parses style names into structured objects.
Multi-Format Input Support
Load documents from five input formats — DOCX, DOC, RTF, TXT, and Markdown — using the same Document constructor. The LoadFormat enum provides constants for explicit format selection (LoadFormat.DOCX, LoadFormat.DOC, LoadFormat.RTF, LoadFormat.TEXT, LoadFormat.MARKDOWN).
Quick Start
Install the package and convert a DOCX file to all three output formats:
pip install aspose-words-fossimport aspose.words_foss as aw
from aspose.words_foss.md_writer import LdmMarkdownWriter
from aspose.words_foss.pdf_writer import LdmPdfWriter
# Load a Word document
doc = aw.Document("report.docx")
# Export to Markdown
LdmMarkdownWriter().write(doc, "report.md")
# Export to PDF
LdmPdfWriter().write(doc, "report.pdf")
# Extract text directly and write it out as plain text
text = doc.text
with open("report.txt", "w", encoding="utf-8") as f:
f.write(text)
print(f"Extracted {len(text)} characters")
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| DOCX | .docx | ✓ | — |
| DOC | .doc | ✓ | — |
| RTF | .rtf | ✓ | — |
| TXT | .txt | ✓ | — |
| Markdown | .md | ✓ | ✓ |
| — | ✓ |
Open Source & Licensing
Aspose.Words FOSS for Python is released under the MIT License. You can use it freely in personal, internal, and commercial projects without license fees. The full source code is available on GitHub at the Aspose Words FOSS organization.