使用insertDocument 将两个文档合并时,合并后保存为pdf 表格展示不完整

代码
image.png (21.6 KB)
源文件
image.png (30.1 KB)
保存后的pdf文件
image.png (53.1 KB)

@blp0124, 能否附上source.docx进行分析?

source.docx (99.2 KB)

@blp0124, 您可以尝试以下代码并检查它是否产生所需的结果:

Document document = new Document("source.docx");

Document doc = (Document)document.deepClone(false);
doc.removeAllChildren();
doc.ensureMinimum();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertDocument(document, ImportFormatMode.KEEP_SOURCE_FORMATTING);

doc.save("aaa.pdf");

我需要的是将两个文档合并,两个文档都有内容,这种方式好像并不能满足我需求

@blp0124, 我的回复基于您在第一篇文章中提供的代码。 在该代码示例中,source.docx 被插入到新文档中。

您能附上第二份文件吗?

response.docx (277.1 KB)

尝试使用 Table table = (Table) document.getChild(NodeType.TABLE, 0, true);
table.setPreferredWidth(PreferredWidth.fromPoints(10)); 设置表格宽度,在生成的pdf中没有生效,使用的版本是21.11

@blp0124, 您是否将 source.docx 中的表插入到 response.docx 的末尾? 您能详细说明一下您的要求吗?如果可能,请提供代码示例。

我的需求是,在前端浏览器,上传多个word文件,由后端将多个word文件合并,并且输出位,docx pdf 与html,

@blp0124, 好的,但我的问题只是关于 Word 文件合并。
您是否尝试将 source.docx 附加到 response.docx 的末尾? 合并文档需要执行哪些步骤? 请提供更多详细信息。 你能写一个伪代码来阐明你的需求吗?

是的,我只需要将两个文档进行合并,不需要其他步骤,合并完成转换为pdf

image.png (31.4 KB)

@blp0124
感谢您报告此问题。 我们已经在我们的内部问题跟踪系统中打开了以下新工单,并将根据 免费支持政策 中提到的条款提供它们的修复:

Issue ID(s): WORDSNET-25783

如果您需要优先支持以及直接联系我们的付费支持管理团队,您可以获得 付费支持服务

@blp0124 请尝试以下解决方案来解决此问题:

Document dstDocument = new Document();
DocumentBuilder builder = new DocumentBuilder(dstDocument);

Document srcDocument = new Document("source.docx");
builder.insertDocument(srcDocument, ImportFormatMode.KEEP_SOURCE_FORMATTING);

// Just add this line to solve the issue.
dstDocument.getCompatibilityOptions().setUseFELayout(true);

dstDocument.save("out.docx");

这个解决方案你能接受吗?