We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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”);<o:p></o:p>

// Set up the document which pages will be copied to. Remove the empty section. <o:p></o:p>

Document dstDoc = new Document();<o:p></o:p>

dstDoc.RemoveAllChildren();<o:p></o:p>

PageNumberFinder finder = new PageNumberFinder(doc);<o:p></o:p>

// Split nodes which are found across pages.<o:p></o:p>

finder.SplitNodesAcrossPages(true);<o:p></o:p>

// Copy all content including headers and footers from the specified pages into the destination document.

ArrayList pageSections = finder.RetrieveAllNodesOnPage(3, 5, NodeType.Section);<o:p></o:p>


foreach (Section section in pageSections)

dstDoc.AppendChild(dstDoc.ImportNode(section, true));


dstDoc.Save(dataDir + “Document Out.docx”);<o:p></o:p>

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

Best regards,