gpt4 book ai didi

java - 如何在Aspose Java中从Word文档中删除特定页面?

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:20 25 4
gpt4 key购买 nike

如何在 Aspose Java 中从 Word 文档中删除特定页面?

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

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

最佳答案

您可以使用“PageSplitter”示例项目来实现您的要求。您可以在 Aspose.Words for Java examples repository at GitHub 中找到 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 合作。

关于java - 如何在Aspose Java中从Word文档中删除特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36712792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com