基于 HTML 的报告被分页撕成碎片
我创建了一个基于 HTML 的报告,该报告可以是可变长度和 C# 中的段数(这就是未使用 Crystal Reports 的原因),并且我无法使用精彩的 http://www.printFriendly.com/,因为该报告是基于内联网的(嘘声,嘶嘶声)。
我创建了一个 media=print CSS 文件,用于使格式尽可能高效地使用纸张和墨水,但我遇到了问题。报告中有一个很长的表格,大约有 50 行表格,每行高度约为:200px。不幸的是,由于自动分页,某些表行被切片,部分表行位于一页上,其余部分位于下一页上。是否有(希望通过 CSS)将分页选项设置为不分隔表格元素(或类似元素)?
谢谢, 亚历克斯
I've created a HTML based report that can be variable lengths and number of segments in C# (which is why Crystal Reports wasn't used) and I can't use the wonderful http://www.printfriendly.com/ as the report is Intranet based (boooo, hiss).
I've created a media=print CSS file that is used to make the formatting as paper and ink efficient as possible but I have a problem. There is a very long table in the report with around 50 table rows, each one around height: 200px. Unfortunately some of the table rows are being sliced due to the automatic page breaking, with part of the table row on one page and the rest on the next page. Is there anyway (hopefully via CSS), to set the pagebreaking options to not seperate table elements (or similar elements)?
Thanks,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
page-break-inside: escape
属性应该控制这一点,但看起来大多数浏览器在tr
或上不支持该功能>td
元素。在我的测试中,Opera 是唯一支持此属性的软件,如以下测试中所使用的:如果您可以使用 Opera,这可能就足够了。另一种选择是使用 Prince 来打印报告,因为它往往对打印有更好的支持样式表功能比浏览器功能多(尽管我没有特别测试此功能)。
The
page-break-inside: avoid
property should control this, but it looks like most browsers don't support that ontr
ortd
elements. In my testing, Opera is the only one that honors this property, as used in the following test:If you can use Opera, this might be good enough. Another option would be to look into Prince for printing your reports, as it tends to have much better support for print stylesheet features than the browsers do (though I haven't tested this feature in particular).
如果您的行高恰好是固定的,您可以计算出一页上可以容纳多少行,然后在每第 n 行上使用
page-break-after:always
强制在适当的位置分页地方。这有点麻烦,但它可能是您的最佳选择。If your row height happens to be fixed, you could figure out how many rows fit on a page, then use
page-break-after: always
on every n-th row to force page breaks in the appropriate places. It's a bit of a hack, but it might be your best option.不幸的是,使用 HTML 不可能可靠地完成您想要的任务。
如果您想要对打印内容进行高级控制,我建议您让报告生成器输出 PDF 或 XPS 而不是 HTML(或者正如 Brian Campbell 建议的那样,使用 Prince 等可以获取 HTML 并将其转换为 PDF 的工具)。
Unfortunately, it is impossible to reliably accomplish what you want with HTML.
If you want a high level of control over what is printed, I suggest you have your report generator output PDF or XPS rather than HTML (or as Brian Campbell advised, by using a tool such as Prince that can take HTML and convert it to PDF).