table{
border-collapse: collapse;
}
1. 该样会导致生成的pdf边框消失的问题。 可替换成如下样式便可
table{
border-spacing: 0;
}
参考:
https://stackoverflow.com/questions/10512324/css-to-pdf-the-css-in-flying-saucer-fs-table-paginate-result-in-border-collap
2.通过xhtmlrenderer生成的pdf文件由于出现空白边框,导致内容可能会挤到另一边造成格式出错的问题
添加该样式
@page {
margin: 0;
}
就能去除大部分的白边
第一步:下载wkhtmkto
pdf
软件,安装在指定的目录,如:C:\htmlTo
Pdf
\wkhtmlto
pdf
,第二步:把安装好的wkhtmlto
pdf
文件目录加到环境变量Path路径
中
,public void convertFile(){HttpURLConnection con = null;URL url = null;Process p = null;String cmd = "html2...
很少写博客,可能心思有点杂,很少沉淀下来。但是偶尔看到很久前写的博文对一些小伙伴有帮助,还是比较开心的。几年前写过一篇 itext 转
pdf
富文本编辑器 想着的一些
问题
,发现留言还不少,刚巧后面有时间,也有些
问题
需要处理的时候,重新弄了一遍。这里贴一下,方便回顾,也方便有需要的小伙伴解决
问题
。以下是 html 转 png 的例子,实际上不管是转
pdf
还是转 png,要解决的还是 html 渲染
过程
中
,html 规范导致的各类
问题
。
前例直通车
<dependency>
public static void htmlTo
PDF
(String
pdf
Path, String htmlPath) throws Exception {
try {
IText
Renderer
renderer
= new IText
Renderer
();
ITextFontResolver fontResolver =
renderer
.getFontResolver();
OutputStre
public int forcePageBreakBefore(LayoutContext c, IdentValue pageBreakValue, boolean pendingPageName) {
I have an issue with some styles after converting this html file to document.div,p{background-color: #ff0000;padding: 100px;border: 10px solid #000;text-align: justify;margin-bottom: 50px;text-indent:...
<table border-
collapse
="
collapse
" border="1px solid blue" width="100%" border="1"><tr>
<th border="1px solid blu...
只能像下面这样分开各个方向写,不能像平时那样直接写border: 1px solid #e8eaec;
border-top: 1px solid #e8eaec;
border-right: 1px solid #e8eaec;
border-bottom: 1px solid #e8eaec;
border-left: 1px...
由于
中
间
使用
了行合并
使用
tr标签page-break-inside:avoid!important;无效,会将合并的两行割裂。
直接设置td宽度,由于行合并导致部分宽度
失效
。
问题
图片