Document extractPages

我在使用 24.12版本aspose-words都指定文件进行页内容提取后,文档的页数正常获取,但页面中的页码无法正常更新,应该如何更新总页码问题
extract-page_result.docx (13.0 KB)

test-page.docx (15.8 KB)

// 加载主文档
        Document doc1 = new Document(sourceFile);
        int pageCount = doc1.getPageCount();
        System.out.println(String.format("输入总页数:%d", pageCount));

        if(pageCount > pageNum){
            // 计算要保留的页面范围
            Document doc2 = doc1.extractPages(0, pageNum);
            System.out.println(String.format("输出总页数:%d", doc2.getPageCount()));
            // 更新所有域
            doc2.updateFields();
            // 更新文档布局
            doc2.updatePageLayout();
            doc2.save(targetFile, SaveFormat.DOCX);
        }else{
            doc1.save(targetFile, SaveFormat.DOCX);
        }

@LXY133 您能更详细地解释一下这个问题吗?正如我在 extract-page_result.docx 中看到的,NUMPAGES 字段被取消了链接,并被替换成了普通文本。

我在wps中创建了test-page.docx,并在文档中的页脚添加了页码设置后保存,然后就用上面的代码进行文档的加载,提取指定的一页并保存为新的文档,没有其他操作,但打开新保存的文档后,就发现页码是错误的

@LXY133 您说得对,Aspose.Words 在提取页面内容时会取消文档页脚中的 NUMPAGES 字段的链接,以保留与原始文档完全相同的内容。您是否希望保留 NUMPAGES 字段的原样,以便在页脚中将值显示为 1 / 1

是的,文档原有的设定要保持一致

@LXY133
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28250

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.