Learn how to convert Word documents to EPUB in Java: https://blog.aspose.com/2021/11/01/convert-word-to-epub-in-java/
Last active
December 2, 2021 07:36
Star
You must be signed in to star a gist
Convert Word Files to EPUB in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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