【问题标题】:How to remove specific page from word document in Aspose Java?如何从 Aspose Java 中的 word 文档中删除特定页面?
【发布时间】:2016-04-19 08:29:43
【问题描述】:

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

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

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

【问题讨论】:

    标签: java aspose aspose.words


    【解决方案1】:

    您可以使用“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 合作,担任开发人员传道者。

    【讨论】:

    • 该解决方案运行良好,但我失去了一些 Word 文档功能。拆分后,我丢失了邮件合并字段。
    • 请在Aspose.Words forum 中发布问题详情以供调查。我与 Aspose 合作,担任开发人员宣传员。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    相关资源
    最近更新 更多