A 100% standalone Word Python API for Processing Word Files
Project description
Python API for Creating, Reading, Manipulating, and Converting Word Documents
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:
-
Document Conversion:
- Convert Word to PDF
- Convert Text to Word or Word to Text
- Convert Word to Images (PNG, JPEG, BMP, SVG)
- Convert Word to HTML
- Convert HTML to Word
- Convert Word to RTF or RTF to Word
- Convert RTF to PDF, HTML
- Convert Word to EPUB
- Convert HTML to PDF
- Convert HTML to Images
- Convert Word to XPS, PostScript, or OFD
-
Document Creation and Manipulation:
- Create, Read, or Update Word Documents
- Merge Word Documents
- Split Word Documents
- Compare Word Documents
- Add Background Color or Picture to Word Documents
- Add, Read, or Remove Document Properties in Word
- Accept or Reject Tracked Changes in Word
-
Document Protection:
-
Mail Merge:
- Perform Mail Merge in Word
-
Text Manipulation:
-
Image and Shape Manipulation:
- Insert Images in Word
- Replace Images in Word
- Extract Images from Word
- Add or Remove Shapes in Word
-
Table Creation and Manipulation:
-
Hyperlink Manipulation:
-
Header and Footer Manipulation:
-
Watermark Manipulation:
-
Bookmark Manipulation:
-
List Manipulation:
-
Comment Manipulation:
-
Form Field Manipulation:
-
Text and Paragraph Formatting:
-
Page Setup:
-
Textbox and OLE Manipulation:
-
Footnote and Endnote Manipulation:
- Insert or Remove Footnotes in Word
- Insert or Remove Endnotes in Word
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file Spire.Doc-12.7.1-py3-none-win_amd64.whl
.
File metadata
- Download URL: Spire.Doc-12.7.1-py3-none-win_amd64.whl
- Upload date:
- Size: 27.0 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7cf1a82272abb41a46372bd67d71bb5b59d3062be32732275d37c471929b432 |
|
MD5 | fa8df2c755462d93e1e7517c617c10b3 |
|
BLAKE2b-256 | 0573cedc7e28cd583ab545468d24ffbc1a8b327fbe6218f037c4e6726b81ea16 |
File details
Details for the file Spire.Doc-12.7.1-py3-none-manylinux1_x86_64.whl
.
File metadata
- Download URL: Spire.Doc-12.7.1-py3-none-manylinux1_x86_64.whl
- Upload date:
- Size: 42.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68b0138f53bc4cb326a6aa904171c0e66e430337fb9ba0c3acaa74eb2ef567a5 |
|
MD5 | b6de6500959af0a6534eab71ee8545dd |
|
BLAKE2b-256 | a728b6e3e998efc7525954fe5adc3db807247fd88b9514b2c22804cb8cc83981 |
File details
Details for the file Spire.Doc-12.7.1-py3-none-macosx_10_7_universal.whl
.
File metadata
- Download URL: Spire.Doc-12.7.1-py3-none-macosx_10_7_universal.whl
- Upload date:
- Size: 48.5 MB
- Tags: Python 3, macOS 10.7+ universal
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e28741779dae5a14e2b5138a5b4a9ec5960a5d6c2d7a2973ac7347e0b8e69cf0 |
|
MD5 | 8ec0ee4c145d59f16cb5fcdb3177fd2f |
|
BLAKE2b-256 | 11696c69479a518822c7295fdaa10a0aed3c95fa3d62676fca077fd20b93b946 |