A 100% standalone Word Python API for Processing Word Files
Project description
Python API for Word Documents Manipulating and Converting
Product Page | Documentation | Examples | Forum | Temporary License | Customized Demo
Spire.Doc for Python is a professional Python API for processing Word documents. Developers can use this independent Python API to create, read, edit, convert, and compare Word documents with any other external dependencies.
Spire.Doc for Python is highly compatible with MS Word. It supports Word 97-2003 /2007/2010/2013/2016/2019 and can convert them to commonly used file formats like XML, RTF, TXT, XPS, EPUB, EMF, HTML, and vice versa. Converting Word Doc/Docx to PDF and HTML to image is also supported.
Standalone Python API
Spire.Doc for Python is an independent Python API to process Word documents. It doesn't requires MS Word or any other third-party tools.
Support for Old and New Word Versions
- Word 97-03
- Word 2007
- Word 2010
- Word 2013
- Word 2016
- Word 2019
Rich Support for Word Document Features
A common use of Spire.Doc for Python is to create Word documents dynamically from scratch. Almost all Word document elements are supported, including pages, sections, headers, footers, digital signatures, footnotes, paragraphs, lists, tables, text, fields, hyperlinks, bookmarks, comments, images, style, background settings, document settings, and protection. Furthermore, drawing objects including shapes, text boxes, images, OLE objects, Latex Math Symbols, MathML Code, and controls are supported as well.
High-Quality File Conversion
By using Spire.Doc for Python, users can save Word Doc/Docx to stream, save as web response and convert Word Doc/Docx to XML, RTF, EMF, TXT, XPS, EPUB, HTML, SVG, ODT, and vice versa. Spire.Doc for Python also supports converting Word Doc/Docx to PDF and HTML to images.
Examples
Create a Word document in Python
from spire.doc.common import *
from spire.doc import *
outputFile = "HelloWorld.docx"
#Create a word document
document = Document()
#Create a new section
section = document.AddSection()
#Create a new paragraph
paragraph = section.AddParagraph()
#Append Text
paragraph.AppendText("Hello World!")
#Save doc file.
document.SaveToFile(outputFile, FileFormat.Docx)
#Close the document object
document.Close()
Convert Word to PDF
from spire.doc import *
from spire.doc.common import *
inputFile = "./Data/ConvertedTemplate.docx"
outputFile = "ToPDF.pdf"
#Create word document
document = Document()
document.LoadFromFile(inputFile)
#Save the document to a PDF file.
document.SaveToFile(outputFile, FileFormat.PDF)
document.Close()
Convert Word to image
from spire.doc import *
from spire.doc.common import *
inputFile = "./Data/ConvertedTemplate.docx"
outputFile = "ToImage.png"
#Create word document
document = Document()
document.LoadFromFile(inputFile)
#Obtain image data in the default format of png,you can use it to convert other image format.
imageStream = document.SaveImageToStreams(0, ImageType.Bitmap)
with open(outputFile,'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
Hashes for Spire.Doc-12.2.1-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97553f130341ea0550dee2386caf760c4f0337c916368ed9697f4c31d9390d81 |
|
MD5 | 37378e75fcc8f5ee2c397dfbf3f41788 |
|
BLAKE2b-256 | 7b477f0ef9690031948d6c30ed8eccbe2d69a395f93bd69f1865c219087bad97 |
Hashes for Spire.Doc-12.2.1-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | affaa16d031049024d25b5ebd3501f06972d054037ce4a0501d600f5ac064034 |
|
MD5 | bf96d29982163ec5f6ac5d3173a5517a |
|
BLAKE2b-256 | 105500894b303ae9536d11d223830cd83476f2ba8434d441005e44da5fad5754 |