Я пытался сегментировать документ docx на несколько документов на основе предопределенных критериев. Ниже приведен мой подход, чтобы разрезать его на абзацы.
try {
FileInputStream in = new FileInputStream(file);
XWPFDocument doc = new XWPFDocument(in);
List<XWPFParagraph> paragraphs = doc.getParagraphs();
for (int idx = 0; idx < paragraphs.size(); idx++) {
XWPFDocument outputDocument = new XWPFDocument();
createParagraphInAnotherDocument(outputDocument, paragraphs.get(idx).getText());
String fullPath = String.format("./content/output/%1$s_%2$s_%3$04d.docx", FileUtils.getFileName(file), getName(), idx);
FileOutputStream outputStream = new FileOutputStream(fullPath);
outputDocument.write(outputStream);
outputDocument.close();
doc.close();
}
} catch (IOException e) {
e.printStackTrace();
}
Хотя я могу извлекать абзацы с помощью приведенного выше кода, я не могу найти способ извлечения страниц. Насколько я понимаю, страницы в слове вызывают беспокойство, и это происходит во время выполнения в приложении слова.