如何在不拆分表格的情况下将 docx 转换为 PDF
我有包含几个表格的动态 docx,我正在尝试转换为 PDF。当我转换为 PDF 时,它涵盖了两页。我使用 Apache POI XWPF 转换器 2.0.2 版本。 在 docx 文件中,一切正常,但是当我转换为 PDF 时,表格会被恶意
有人有任何想法或更好的库来将 docx 转换为 pdf?
PdfOptions options = PdfOptions.getDefault();
options.fontProvider((familyName, encoding, size, style, color) -> {
try {
BaseFont baseFont = BaseFont.createFont("fonts/times.ttf", encoding, BaseFont.EMBEDDED);
return new Font(baseFont, size, style, color);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
PdfConverter.getInstance().convert(document, out, options);
I have dynamics docx with few tables and I'm trying to convert to a PDF. When I converted to PDF then it covers two pages. I use Apache POI XWPF converter in 2.0.2 version.
In docx file everything is okey but when I convert to PDF then tables are spited
Someone have any idea or better library to convert docx to pdf?
PdfOptions options = PdfOptions.getDefault();
options.fontProvider((familyName, encoding, size, style, color) -> {
try {
BaseFont baseFont = BaseFont.createFont("fonts/times.ttf", encoding, BaseFont.EMBEDDED);
return new Font(baseFont, size, style, color);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
PdfConverter.getInstance().convert(document, out, options);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有库可以将
doc[x]
文件转换为格式完全正确的 PDF。唯一可以做到这一点的程序是Word 本身。我通过在 PowerShell 脚本中使用 Word API 实现了这一点:
是的,这不是最好的解决方案,它严重依赖于计算机中安装的 Microsoft Office 以及随之而来的许多其他问题解决方案...但它是唯一能够按照我想要的方式格式化我的文档的解决方案。
该脚本采用三个参数
There is no library to convert a
doc[x]
file into a completely correctly formatted PDF. The only program that can do that is Word itself.I have achieved this by using the Word API in a
PowerShell
script:Yes it is not the best solution and it is heavily dependent on having Microsoft Office installed in the machine and a lot of other problems that accompany this solution... But it is the only solution that formatted my documents exactly how I wanted them.
The script takes three arguments