arbit
V2EX  ›  问与答

html 转 pdf

By arbit at 2021 年 6 月 3 日 · 3867 次点击

大佬们,java 有没有什么开源包可以将 html 转 pdf 或者 word 文档,之前用的 itextpdf 老是掉样式

15 条回复  •  2021-06-04 13:28:32 +08:00
ynkkdev
   1
ynkkdev  
   2021 年 6 月 3 日
上无头浏览器,不然 js 你咋渲染
yuancoder
   2
yuancoder  
   2021 年 6 月 3 日   ❤️ 1
wkhtmltopdf,wkhtmltoimage
abai
   3
abai  
   2021 年 6 月 3 日
wlwlwan
   4
wlwlwan  
   2021 年 6 月 3 日
print friendly and pdf 可以一试
windirt
   5
windirt  
   2021 年 6 月 3 日
pandoc 可以吗?
thomaschen2019
   6
thomaschen2019  
   2021 年 6 月 3 日
miaomiao2014
   7
miaomiao2014  
   2021 年 6 月 3 日
chrome 有打印能保存为 pdf.
lau52y
   8
lau52y  
   2021 年 6 月 3 日
我是用的 pyppeteer
shyrock
   9
shyrock  
   2021 年 6 月 3 日
@yuancoder #2 wkhtmltopdf 转换表格在分页的时候会导致 thead 跟 tbody 重叠,一直没解决。
yuancoder
   10
yuancoder  
   2021 年 6 月 3 日
@shyrock #9 是最新版吗?我之前用老版本也出现过这种情况
shyrock
   11
shyrock  
   2021 年 6 月 3 日
@shyrock #9 最新版
tghoul
   12
tghoul  
   2021 年 6 月 3 日
itextpdf 确实不好用,java 的 pdf 库推荐这个 https://github.com/danfickle/openhtmltopdf
446ENzu91KZ73A33
   13
446ENzu91KZ73A33  
   2021 年 6 月 3 日
有前端单独部署的服务,行吗?叫啥忘了,需要的话我就翻翻
wdlth
   14
wdlth  
   2021 年 6 月 4 日
试了很多种,还是用浏览器打印的效果比较好,所以我们这已经甩锅给前端做了……
没什么特殊排版的就后端用 Flying Saucer 配合 PDFBox 。
arbit
   15
arbit  
OP
   2021 年 6 月 4 日
@mu666 谢谢大佬们了 专门搭建个单独服务好像有点浪费了,其实只是要实现个网页上富文本编辑器 编辑页面后能导出成文档的功能而已
© 2026 V2EX · 43ms · 3.9.8.5