Skip to main content

Python API for Creating, Reading, Manipulating, and Converting Word Documents

Spire.Doc for Python

Product Page | Documentation | Examples | Forum | Temporary License | Customized Demo

Spire.Doc for Python is a powerful and easy-to-use Word document processing library. It empowers developers to create, read, modify, and convert Word documents in Python applications without the need for Microsoft Word or any other third-party software.

Supported Word Versions

The following are the Word versions supported by Spire.Doc for Python:

  • Word 97-03
  • Word 2007
  • Word 2010
  • Word 2013
  • Word 2016
  • Word 2019

Supported Operating Systems

The following are the operating systems supported by Spire.Doc for Python:

  • Windows
  • Linux
  • MacOS

Key Features of Spire.Doc for Python

Spire.Doc for Python provides a comprehensive set of features for working with various Word formats including DOC, DOCX, DOCM, DOT, DOTX, DOTM, and more.

The following list shows some key features offered by Spire.Doc for Python:

  1. Document Conversion:

  2. Document Creation and Manipulation:

  3. Document Protection:

  4. Mail Merge:

    • Perform Mail Merge in Word
  5. Text Manipulation:

  6. Image and Shape Manipulation:

  7. Table Creation and Manipulation:

  8. Hyperlink Manipulation:

  9. Header and Footer Manipulation:

  10. Watermark Manipulation:

  11. Bookmark Manipulation:

  12. List Manipulation:

  13. Comment Manipulation:

  14. Form Field Manipulation:

  15. Text and Paragraph Formatting:

  16. Page Setup:

  17. Textbox and OLE Manipulation:

  18. Footnote and Endnote Manipulation:

Examples

Create a Word Document from Scratch in Python

The following code shows how to create a Word document from scratch and add content to it using Python and Spire.Doc for Python:

from spire.doc import *	
from spire.doc.common import *

# Create a Document object
doc = Document()

# Add a section
section = doc.AddSection()

# Set the page margins
section.PageSetup.Margins.All = 40

# Add a title
titleParagraph = section.AddParagraph()
titleParagraph.AppendText("Introduction of Spire.Doc for Python")

# Add two paragraphs
bodyParagraph_1 = section.AddParagraph()
bodyParagraph_1.AppendText("Spire.Doc for Python is a professional Python library designed for developers to " +
                           "create, read, write, convert, compare and print Word documents in any Python application " +
                           "with fast and high-quality performance.")

bodyParagraph_2 = section.AddParagraph()
bodyParagraph_2.AppendText("As an independent Word Python API, Spire.Doc for Python doesn't need Microsoft Word to " +
                           "be installed on neither the development nor target systems. However, it can incorporate Microsoft Word " +
                           "document creation capabilities into any developers' Python applications.")

# Apply heading1 to the title
titleParagraph.ApplyStyle(BuiltinStyle.Heading1)

# Create a style for the paragraphs
style2 = ParagraphStyle(doc)
style2.Name = "paraStyle"
style2.CharacterFormat.FontName = "Arial"
style2.CharacterFormat.FontSize = 13
doc.Styles.Add(style2)
bodyParagraph_1.ApplyStyle("paraStyle")
bodyParagraph_2.ApplyStyle("paraStyle")

# Set the horizontal alignment of the paragraphs
titleParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center
bodyParagraph_1.Format.HorizontalAlignment = HorizontalAlignment.Left
bodyParagraph_2.Format.HorizontalAlignment = HorizontalAlignment.Left

# Set the after spacing
titleParagraph.Format.AfterSpacing = 10
bodyParagraph_1.Format.AfterSpacing = 10

# Save to file
doc.SaveToFile("output/WordDocument.docx", FileFormat.Docx2019)

Convert a Word Document to PDF in Python

The following code shows how to convert a Word document to PDF using Python and Spire.Doc for Python:

from spire.doc import *
from spire.doc.common import *

# Create word document
document = Document()

# Load a doc or docx file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx")

#Save the document to PDF
document.SaveToFile("output/ToPDF.pdf", FileFormat.PDF)
document.Close()

Convert a Word Document to Images in Python

The following code shows how to convert a Word document to images using Python and Spire.Doc for Python:

from spire.doc import *
from spire.doc.common import *

# Create a Document object
document = Document()

# Load a Word file
document.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx")

# Loop through the pages in the document
for i in range(document.GetPageCount()):

    # Convert a specific page to bitmap image
    imageStream = document.SaveImageToStreams(i, ImageType.Bitmap)

    # Save the bitmap to a PNG file
    with open('Output/ToImage-{0}.png'.format(i),'wb') as imageFile:
        imageFile.write(imageStream.ToArray())

document.Close()

Product Page | Documentation | Examples | Forum | Temporary License | Customized Demo

Release files for spire-doc 14.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for spire-doc 14.9.1
File
spire_doc-14.9.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
spire_doc-14.9.1-py3-none-manylinux_2_34_x86_64.whl Python 3 none Linux glibc 2.34+ x86-64 Details
spire_doc-14.9.1-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
spire_doc-14.9.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
spire_doc-14.9.1-py3-none-macosx_10_7_universal.whl Python 3 none macOS 10.7+ universal (x86-64, i386, PPC64, PPC) Details

Total release size: 183.4 MB

Release files / spire_doc-14.9.1-py3-none-win_amd64.whl

Download URL spire_doc-14.9.1-py3-none-win_amd64.whl
Size 29.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
5e1a277a0fe11eaf86f7cf1076a03eded95dfd0bb2439352636464b804cc6a33
BLAKE2b-256 checksum
How to use checksums
0bc8dd6d32f9a3d88b2c8cc1c3aed6a616301a6c3bdd4bc81be0bf3dcca26927
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / spire_doc-14.9.1-py3-none-manylinux_2_34_x86_64.whl

Download URL spire_doc-14.9.1-py3-none-manylinux_2_34_x86_64.whl
Size 45.1 MB
Tags Linux glibc 2.34+ x86-64 Python 3
SHA-256 checksum
How to use checksums
259c6bd0362d979a08165eca641f4702d3d25c73270baa902402d8586f9198ee
BLAKE2b-256 checksum
How to use checksums
5d3262d4d5a405df4d04d18caf2cfd308e90091057cc0c7e4737c2248fb934bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / spire_doc-14.9.1-py3-none-manylinux2014_aarch64.whl

Download URL spire_doc-14.9.1-py3-none-manylinux2014_aarch64.whl
Size 25.7 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
d11a6004e4e6da31f53c7562fc5c5f17d8c9d7009c77440b180a827746ceeea6
BLAKE2b-256 checksum
How to use checksums
6c6fa127310b6d5e7db8674d3f6797f5219e0024a03863515dede98f1876095d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / spire_doc-14.9.1-py3-none-macosx_11_0_arm64.whl

Download URL spire_doc-14.9.1-py3-none-macosx_11_0_arm64.whl
Size 29.5 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bf2982e2a850124047a5e15da45433c811b89bb41a5db42fff0e9d5231259876
BLAKE2b-256 checksum
How to use checksums
15a41f61d7f302e9042c8c064467a05d4a81c0c53c8137c28fa6b77d3c5febf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / spire_doc-14.9.1-py3-none-macosx_10_7_universal.whl

Download URL spire_doc-14.9.1-py3-none-macosx_10_7_universal.whl
Size 53.9 MB
Tags Python 3 macOS 10.7+ universal (x86-64, i386, PPC64, PPC)
SHA-256 checksum
How to use checksums
bf2e537990405d6fdf324f76fa839c3a2fa35ce10169ddab666829aefa548e62
BLAKE2b-256 checksum
How to use checksums
42a307750ceb3ff1fe8df6b36eadd48bfa1ea14f8fa1c09beb57e4387787784c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release history Release notifications | RSS feed

This release

14.9.1 This release

5 release files

14.8.1

5 release files

14.6.2

5 release files

14.4.2

5 release files

14.1.6

5 release files

13.8.0

4 release files

13.6.4

4 release files

13.4.6

4 release files

13.3.8

4 release files

13.3.7

4 release files

13.1.0

3 release files

12.7.1

3 release files

12.6.0

3 release files

12.4.0

3 release files

12.3.2

2 release files

12.2.1

2 release files

11.8.1

2 release files

11.8.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page