Extract first five page

Hi
How can i extract only 5 first page from a document as a new Word document?

I use Asp.net and c# 2008 and aspose.word 13.2.0.0

Hi Saeed,

Thanks for your inquiry.

Please note that Microsoft Word documents are flow documents and are not natively laid out into lines and pages. I think, in your case you can achieve splitting of document into pages by using the utility methods available in the attached ‘PageNumberFinder’ class. For example, you can use the code like below to extract pages to an external document.

Document doc = new Document("Document.docx");
// Set up the document which pages will be copied to. Remove the empty section.
Document dstDoc = new Document();
dstDoc.RemoveAllChildren();
PageNumberFinder finder = new PageNumberFinder(doc);
// Split nodes which are found across pages.
finder.SplitNodesAcrossPages(true);
// Copy all content including headers and footers from the specified pages into the destination document.
ArrayList pageSections = finder.RetrieveAllNodesOnPage(3, 5, NodeType.Section);

foreach(Section section in pageSections)
    dstDoc.AppendChild(dstDoc.ImportNode(section, true));

dstDoc.Save(dataDir + "Document Out.docx");

If you have any issues, please attach your document here for testing.
Best regards,