Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 19, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/83eb6b2571f10bcb93c803e6bc9af881 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/83eb6b2571f10bcb93c803e6bc9af881 to your computer and use it in GitHub Desktop.
Convert Word Documents to EPUB in Python
import aspose.words as aw
# Load the Word document
doc = aw.Document("document.docx")
# Create an object for save options
saveOptions = aw.saving.HtmlSaveOptions()
# Set the desired encoding
saveOptions.encoding = "utf-8"
# Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
# which allows you to limit the size of each HTML part. This is useful for readers which cannot read
# HTML files greater than a certain size e.g 300kb.
saveOptions.document_split_criteria = aw.saving.DocumentSplitCriteria.HEADING_PARAGRAPH
# Enable export of document properties
saveOptions.export_document_properties = True
# Specify save format
saveOptions.save_format = aw.SaveFormat.EPUB
# Convert Word document to EPUB
doc.save("word-to-epub.epub", saveOptions)
import aspose.words as aw
# Load the Word document
doc = aw.Document("document.docx")
# Convert Word document to EPUB
doc.save("word-to-epub.epub")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment