
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
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.
The following are the Word versions supported by Spire.Doc for Python:
The following are the operating systems supported by 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:
Document Creation and Manipulation:
Document Protection:
Mail Merge:
Text Manipulation:
Image and Shape Manipulation:
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:
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)
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()
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
FAQs
A 100% standalone Word Python API for Processing Word Files
We found that spire-doc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.