尝试使用[Docx4J.toPDF]方法将单词转换为PDF时发生异常。 我怀疑这是因为我使用了[XmlUtils.deepCopy]方法将表复制为word。 因为我在项目中有一个列表,所以我根据列表数复制表
Docx4j使用标签$ {name}替换内容,已成功复制表格并生成了单词,但是在将单词转换为PDF时出错。 没有表格副本的其他单词通常可以转换为PDF
public static void replaceTcContentList(Body body, Tbl tbl, List<Map> valueMapList, WordprocessingMLPackage wordMLPackage) throws Exception {
// copy table
for (int i=1; i<valueMapList.size(); i++) {
Tbl copyTbl = XmlUtils.deepCopy(tbl);
body.getContent().add(copyTbl);
body.getContent().add(new P());
}
// Retrieve the entire table
MyTblFinder tblFinder = new MyTblFinder();
new TraversalUtil(body, tblFinder);
for(int i=1; i<tblFinder.getTbls().size(); i++){
Tbl childTbl = tblFinder.getTbls().get(i);
Map<String, String> valueMap = valueMapList.get(i-1);
replaceTcContent(childTbl, valueMap, "${QRCode}", 65, 65, wordMLPackage);
}
}
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:106)
at org.docx4j.Docx4J.toFO(Docx4J.java:734)
at org.docx4j.Docx4J.toPDF(Docx4J.java:749)
at com.kf.utils.word.Doc4jUtils2.plProcessCard(Doc4jUtils2.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
at
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Exception writing Document to OutputStream: org.apache.fop.fo.ValidationException:
Property ID "XXXX" (found on "fo:inline") previously used; ID values must be unique within a document! (See position 7:7519)
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:56)
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:18)
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:253)
at
我知道复制的表中字段XXX的ID不是唯一的,我想对其进行修改,但是我不知道如何对其进行修改。