Hi,
Aspose words version: 22.5.0
We are using special bookmark names to determine each content of a document.
the following code is being called after taking the proper start & end page # of each bookmark.
The idea is the first bookmark is on the 1st page until the 7th page.
While the second bookmark is from the 8th page until the 14th page.
In the given sample document there are 14pages.
private Document extractDocumentPages(Document sourceDoc, int startPage, int count) throws Exception {
Document splitDocument = new Document();
splitDocument.removeAllChildren();
// Extract pages
Document extractedPages = sourceDoc.extractPages(startPage, count);
// Copy sections from extracted pages to split document
for (Section section : extractedPages.getSections()) {
Section newSection = (Section) splitDocument.importNode(section, true);
splitDocument.appendChild(newSection);
// Keep the section start type from the original document
newSection.getPageSetup().setSectionStart(section.getPageSetup().getSectionStart());
}
// Ensure the first section starts on a new page if it's not the very first page
if (startPage > 1 && splitDocument.getFirstSection() != null) {
splitDocument.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
}
return splitDocument;
}
The first bookmark which calls extractDocumentPages from page 1 to 7 is working correctly.
which is consumed by extractDocumentPages(0, 7);
However when I extract from page 7 to 14
which is consumed by extractDocumentPages(7, 7);
it throws an error This instance is not attached to a document.
The specific error is encountered on sourceDoc.extractPages(startPage, count)
java.lang.IllegalStateException: This instance is not attached to a document.
at com.aspose.words.LayoutCollector.zzZ67(Unknown Source) ~[aspose.jar:22.5.0]
at com.aspose.words.LayoutCollector.getStartPageIndex(Unknown Source) ~[aspose.jar:22.5.0]
at com.aspose.words.zzZ3T.zzYxS(Unknown Source) ~[aspose.jar:22.5.0]
at com.aspose.words.zzZ3T.extractPages(Unknown Source) ~[aspose.jar:22.5.0]
at com.aspose.words.Document.extractPages(Unknown Source) ~[aspose.jar:22.5.0]
Any help is appreciated
sample_failure_doc.docx (59.2 KB)