Skip to main content

A 100% standalone Word Python API for Processing Word Files

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

spire_doc-14.4.2-py3-none-win_amd64.whl (28.3 MB view details)

Uploaded Python 3Windows x86-64

spire_doc-14.4.2-py3-none-manylinux_2_31_x86_64.whl (44.0 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

spire_doc-14.4.2-py3-none-manylinux2014_aarch64.whl (24.8 MB view details)

Uploaded Python 3

spire_doc-14.4.2-py3-none-macosx_11_0_arm64.whl (28.7 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

spire_doc-14.4.2-py3-none-macosx_10_7_universal.whl (52.2 MB view details)

Uploaded Python 3macOS 10.7+ universal (x86-64, i386, PPC64, PPC)

File details

Details for the file spire_doc-14.4.2-py3-none-win_amd64.whl.

File metadata

  • Download URL: spire_doc-14.4.2-py3-none-win_amd64.whl
  • Upload date:
  • Size: 28.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for spire_doc-14.4.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 fca807d60451934c9d648465c4dac24f77c42d8a4ac266b048835fce4f7399e3
MD5 84d5c75e60a6bddbbee6d87034f5a605
BLAKE2b-256 294d0a26c3c2a38d4c3861090bebd64ff58a4454f5913f7cf58e33da2aa3dd6c

See more details on using hashes here.

File details

Details for the file spire_doc-14.4.2-py3-none-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for spire_doc-14.4.2-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 c5b4fb81972df87a2562f230b562a2a5dfdc2c0384bc3f32b1d5dbd09f02a6ed
MD5 3f72a29085c939f4d2380fb6b061d3e6
BLAKE2b-256 84932bcbf0aa8a4b62adbf1f54a3b78ad2b001a10ec7292f1c765785dc70f84f

See more details on using hashes here.

File details

Details for the file spire_doc-14.4.2-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for spire_doc-14.4.2-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fb19eae448059c67d1ea90a06bcedf15949652ecffd30b5474dd3e659afc101e
MD5 ff2f8d9957a0cd884f52cfce626d376f
BLAKE2b-256 430639a56c992293de47dc3c9c80481d264d2e33e0d089c54ec651617e97ecc1

See more details on using hashes here.

File details

Details for the file spire_doc-14.4.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for spire_doc-14.4.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2058be6fb8a70bb05e355c6f6077630d3b270fb18e2b1bbf8a27f82899085332
MD5 77155e3508d4001a79d761ddb93acdbb
BLAKE2b-256 b82151718328f020640436f1296cfadb650d74e656a15fad37e163670adeaf2e

See more details on using hashes here.

File details

Details for the file spire_doc-14.4.2-py3-none-macosx_10_7_universal.whl.

File metadata

File hashes

Hashes for spire_doc-14.4.2-py3-none-macosx_10_7_universal.whl
Algorithm Hash digest
SHA256 21d93dd04074d55020f95df4729fba35919ca4425f980a04aaa6eb75e9514e94
MD5 ef8dfb1a2b7096ceb2d0a6c15875cc6d
BLAKE2b-256 2bcb7e1e89771792ddc56961a4b080963a92e421faed81d8c1579cf7988a3967

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page