简体   繁体   中英

How to remove specific page from word document in Aspose Java?

How to remove specific page from word document in Aspose Java ?

My requirement is, i have one word document from which i need only first page ?

so either i can remove all the pages except first one or i can create new document read first page from the document and write it to new document.

You can achieve your requirements using the "PageSplitter" example project. You can find PageSplitter code in Aspose.Words for Java examples repository at GitHub . Please use following code example to extract the first page from Word document.

//Load the document
Document doc = new Document(MyDir + "in.docx");

// Create and attach collector to the document before page layout is built.
LayoutCollector layoutCollector = new LayoutCollector(doc);

// Split nodes in the document into separate pages.
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);

//Get the first page of document
Document newDoc = splitter.GetDocumentOfPage(1);
newDoc.save(MyDir + "Out.docx");

I work with Aspose as Developer evangelist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM