Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 2, 2021 07:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aspose-com-gists/2518d50671733da016a13e8cf48667c9 to your computer and use it in GitHub Desktop.
Convert Word Files to EPUB in Java
// Load the Word document
Document doc = new Document("document.docx");
// Create an object for save options
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
// Set the desired encoding
saveOptions.setEncoding(Charset.forName("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.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);
// Enable export of document properties
saveOptions.setExportDocumentProperties(true);
// Specify save format
saveOptions.setSaveFormat(SaveFormat.EPUB);
// Convert Word document to EPUB
doc.save("word-to-epub.epub", saveOptions);
// Load the Word document
Document doc = new 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