版本:23.8
编程语言:java
问题截图:
源文件中序号样式
源文件:
关于报送专利转化运用专项行动实施情况总结的报告 (1).docx (32.0 KB)
您遇到的 DOCX → PDF 转换后编号样式变化,类似于社区中报告的编号/字段在转换后被重新计算或重置的情况【2】。这表明在某些情况下 Aspose.Words 处理编号字段时的行为可能会导致样式变化,但并不一定是使用方式的问题。
在保存前强制更新字段
// 加载文档
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。
使用 PdfSaveOptions 并显式打开字段更新
com.aspose.words.PdfSaveOptions opts = new com.aspose.words.PdfSaveOptions();
opts.setUpdateFields(true); // 保存时重新计算字段
doc.save("out.pdf", opts);
尝试使用更新的版本
如果条件允许,可以在更高版本(如 23.9 或更高)上进行测试,观察是否仍然出现相同问题。
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)