Last active
November 11, 2022 04:04
-
-
Save aspose-com-gists/163f03e6cd53fd757db6b4dc041e797c to your computer and use it in GitHub Desktop.
Split Word Documents using 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
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a Word document | |
Document doc = new Document("Word.docx"); | |
// Split nodes in the document into separate pages | |
DocumentPageSplitter splitter = new DocumentPageSplitter(doc); | |
// Get part of the document | |
Document pageDoc = splitter.getDocumentOfPageRange(3,6); | |
pageDoc.save("SplitDocumentByPageRange.docx"); |
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
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open a Word document | |
Document doc = new Document("Word.docx"); | |
// Split nodes in the document into separate pages | |
DocumentPageSplitter splitter = new DocumentPageSplitter(doc); | |
// Save each page as a separate document | |
for (int page = 1; page <= doc.getPageCount(); page++) | |
{ | |
Document pageDoc = splitter.getDocumentOfPage(page); | |
pageDoc.save("SplitDocumentByPage_" + page + ".docx"); | |
} |
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 a Word DOCX document | |
Document doc = new Document("word.docx"); | |
for (int i = 0; i < doc.getSections().getCount(); i++) { | |
// Split a document into smaller parts, in this instance split by section | |
Section section = doc.getSections().get(i).deepClone(); | |
// Create a new document | |
Document newDoc = new Document(); | |
newDoc.getSections().clear(); | |
// Add section | |
Section newSection = (Section) newDoc.importNode(section, true); | |
newDoc.getSections().add(newSection); | |
// Save each section as a separate document | |
newDoc.save("splitted_" + i + ".docx"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment