Python: Convert Word to XPS, PostScript, or OFD

Converting Word documents to XPS, PostScript, and OFD documents is of significant importance. Firstly, this conversion makes it easier to share and display documents across different platforms and applications, as these formats typically have broader compatibility.

Secondly, converting to these formats can preserve the document's formatting, layout, and content, ensuring consistent display across different systems.

Additionally, XPS and OFD formats support high-quality printing, helping to maintain the visual appearance and print quality of the document. The PostScript format is commonly used for printing and graphic processing, converting to PostScript can ensure that the document maintains high quality when printed.

In this article, you will learn how to convert Word to XPS, PostScript, or OFD with Python using Spire.Doc for Python.

Install Spire.Doc for Python

This scenario requires Spire.Doc for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip commands.

pip install Spire.Doc

If you are unsure how to install, please refer to this tutorial: How to Install Spire.Doc for Python on Windows

Convert Word to XPS in Python

The Document.SaveToFile(filename:str, FileFormat.XPS) method provided by Spire.Doc for Python can convert a Word document to XPS format. The detailed steps are as follows:

  • Create an object of the Document class.
  • Use the Document.LoadFromFile() method to load the Word document.
  • Use the Document.SaveToFile(filename:str, FileFormat.XPS) method to convert the Word document to an XPS document.
  • Python
from spire.doc import *
from spire.doc.common import *

# Create a Document object
doc = Document()

# Load a Word document
doc.LoadFromFile("Sample.docx")

# Save the loaded document as an XPS document
doc.SaveToFile("Result.xps", FileFormat.XPS)

# Close the document object and release the resources occupied by the document object
doc.Close()
doc.Dispose()

Python: Convert Word to XPS, PostScript, or OFD

Convert Word to PostScript in Python

With Document.SaveToFile(filename:str, FileFormat.PostScript) method in Spire.Doc for Python, you can convert a Word document to PostScript format. The detailed steps are as follows:

  • Create an object of the Document class.
  • Use the Document.LoadFromFile() method to load the Word document.
  • Use the Document.SaveToFile(filename:str, FileFormat.PostScript) method to convert the Word document to a PostScript document.
  • Python
from spire.doc import *
from spire.doc.common import *

# Create a Document object
doc = Document()

# Load a Word document
doc.LoadFromFile("Sample.docx")

# # Save the loaded document as a PostScript document
doc.SaveToFile("Result.ps", FileFormat.PostScript)

# Close the document object and release the resources occupied by the document object
doc.Close()
doc.Dispose()

Python: Convert Word to XPS, PostScript, or OFD

Convert Word to OFD in Python

By utilizing the Document.SaveToFile() method in the Spire.Doc for Python library and specifying the file format as FileFormat.OFD, you can save a Word document as an OFD file format. The detailed steps are as follows:

  • Create an object of the Document class.
  • Use the Document.LoadFromFile() method to load the Word document.
  • Use the Document.SaveToFile(filename:str, FileFormat.OFD) method to convert the Word document to an OFD document.
  • Python
from spire.doc import *
from spire.doc.common import *

# Create a Document object
doc = Document()

# Load a Word document
doc.LoadFromFile("Sample.docx")

# Save the loaded document as an OFD document
doc.SaveToFile("Result.ofd", FileFormat.OFD)

# Close the document object and release the resources occupied by the document object
doc.Close()
doc.Dispose()

Python: Convert Word to XPS, PostScript, or OFD

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.