我正在使用专有的第三方报告工具,该工具具有将报告的 HTML 版本转换为 PDF 的功能。我无法直接控制 PDF 转换的完成方式。但是,我可以控制 HTML 的 CSS,这会间接影响生成的 PDF。它真的只是在桌子上有麻烦。我在其他 pdf 转换器工具中也看到过类似的问题。例如:
- 单个表格的多个标题行不会在 PDF 的每一页上重复。
- 行单元格中间的分页
- 在表格标题和表格本身之间分页。
将 CSS 样式应用于 HTML 表格以便在将 HTML 转换为 PDF 时产生最佳结果的最佳实践有哪些?
I'm using a proprietary 3rd party reporting tool that has a feature which will convert the HTML version of the report and convert it to a PDF. I have no direct control over how the PDF conversion is done. However, I can control the CSS of the HTML which indirectly affects the generated PDF. It really only has trouble with tables. I've seen similar problems with other pdf-converter tools. Things like:
- multiple header rows for a single table don't get repeated on each page of the PDF.
- page breaking in the middle of row cells
- page breaking in between the table caption and the table itself.
What are good best practices for applying CSS styling to HTML tables so that it produces the best results when the HTML is converted to a PDF?
发布评论
评论(2)
您可以尝试设计您的页面样式,尤其是。该表,用于打印媒体,即首先
。这至少可以节省您调用第三方报告工具的时间。
我还会检查 PDF 页面的可用宽度是否小于您的(目标)页面宽度。听起来与您的问题有关(列表中的#2 和#3)。
You may try to style your page, esp. the table, for the print media i.e.
<link rel="stylesheet" media="print" ...
first. That would at least save you some time from calling the 3rd party reporting tool.I'd also check whether the available width of the PDF page is less than your (targeted) page width. It sounds like related to your issues (#2 and #3 in your list).
1 使用显示:table-header-group;在你的CSS
2 & #3 你可以在 css 中使用分页符:page-break-before:always、page-break-after:always 和 page-break-inside:avoid
1 use display: table-header-group; in ur css
2 & #3 you can use page breaks: page-break-before:always, page-break-after:always and page-break-inside:avoid in ur css