docx转PDF,序号样式变更

版本:23.8
编程语言:java

问题截图:

源文件中序号样式

源文件:
关于报送专利转化运用专项行动实施情况总结的报告 (1).docx (32.0 KB)

@ZhonghaoSun

您遇到的 DOCX → PDF 转换后编号样式变化,类似于社区中报告的编号/字段在转换后被重新计算或重置的情况【2】。这表明在某些情况下 Aspose.Words 处理编号字段时的行为可能会导致样式变化,但并不一定是使用方式的问题。

常用的临时规避方案

  1. 在保存前强制更新字段

    // 加载文档
    com.aspose.words.Document doc = new com.aspose.words.Document("src.docx");
    // 更新所有域(包括编号域)
    doc.updateFields();
    // 更新页面布局,确保列表重新计算
    doc.updatePageLayout();
    // 保存为 PDF,使用默认的 PdfSaveOptions
    doc.save("out.pdf");
    

    updateFields() 会重新计算列表/编号域的值,updatePageLayout() 确保布局刷新后再生成 PDF。

  2. 使用 PdfSaveOptions 并显式打开字段更新

    com.aspose.words.PdfSaveOptions opts = new com.aspose.words.PdfSaveOptions();
    opts.setUpdateFields(true);   // 保存时重新计算字段
    doc.save("out.pdf", opts);
    
  3. 尝试使用更新的版本
    如果条件允许,可以在更高版本(如 23.9 或更高)上进行测试,观察是否仍然出现相同问题。

后续建议

  • 将出现问题的 .docx(已上传)和对应的 PDF 结果一起提交到论坛,便于我们在内部复现并定位根因。
  • 若上述代码仍未解决,请在本帖回复并附上最小复现示例(仅包含出现编号的段落),我们会进一步跟进。

Aspose.Words for Java 本身是支持 DOCX → PDF 转换的【3】。当前表现为编号样式异常,可能与产品在处理编号字段时的行为有关,建议使用上述方式临时规避,并关注后续版本的修复。

@ZhonghaoSun
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-28954

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.

能否通过修改源文件来避免呢

@ZhonghaoSun 部分问题可以通过更改列表项编号样式来解决。例如:

Document doc = new Document("C:\\Temp\\in.docx");
    
for (Paragraph p : (Iterable<? extends Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true))
{
    if (p.isListItem() && p.getListFormat().getListLevel().getNumberStyle() == NumberStyle.TRAD_CHIN_NUM_1)
        p.getListFormat().getListLevel().setNumberStyle(NumberStyle.SIMP_CHIN_NUM_1);
}
    
doc.save("C:\\Temp\\out.pdf");

out.pdf (47.4 KB)