Skip to main content

A 100% standalone Word Python API for Processing Word Files

Project description

Python API for Word Documents Manipulating and Converting

Foo

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


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

Spire.Doc-11.10.0-py3-none-win_amd64.whl (26.3 MB view hashes)

Uploaded Python 3 Windows x86-64

Spire.Doc-11.10.0-py3-none-manylinux1_x86_64.whl (41.9 MB view hashes)

Uploaded Python 3

Supported by

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