1

如何从 Aspose Java 中的 word 文档中删除特定页面?

我的要求是,我有一个 word 文档,我只需要第一页吗?

所以我可以删除除第一页以外的所有页面,或者我可以创建新文档,从文档中读取第一页并将其写入新文档。

4

1 回答 1

0

您可以使用“PageSplitter”示例项目来满足您的要求。您可以在 GitHub 的 Aspose.Words for Java 示例存储库中找到 PageSplitter 代码。请使用以下代码示例从 Word 文档中提取第一页。

//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");

我与 Aspose 合作,担任开发人员传道者。

于 2016-04-21T07:07:33.163 回答