Aspose word : Getting one page of a word document

Hi Karine,


Thanks for the additional information. Please find attached a couple of input/output Word documents and try executing the following code snippet. You’ll notice that in out.docx, the first two pages are swapped.
Document doc = new Document(“C:\Temp\input.docx”);

Document finalDoc = (Document)doc.deepClone(true);
finalDoc.removeAllChildren();

LayoutCollector layoutCollector = new LayoutCollector(doc);
doc.updatePageLayout();
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
for (int i = 1; i <= doc.getPageCount(); i++)
{
Document pageDoc = splitter.getDocumentOfPage(i);
finalDoc.appendDocument(pageDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
}

Section secPageSec = finalDoc.getSections().get(1);
finalDoc.getSections().insert(0, secPageSec.deepClone(true));
secPageSec.remove();

finalDoc.save(“C:\temp\out.docx”);

I hope, this helps.

Best regards,