【问题标题】:How can I calculate where a table is cut?如何计算桌子的切割位置?
【发布时间】:2017-08-31 08:19:39
【问题描述】:

我已经生成了一个带有https://gist.github.com/MartinThoma/056183bc0862a787a8d4e8fe57e51f3f 的大表格的简单 HTML 页面

现在我认为标准打印选项是 300dpi,而这个 A4 页面有 2480 像素 x 3508 像素 (source)

Google Chrome PDF 打印插件在第 7 列 / 处剪切页面:

但是当我计算宽度时

var width_total = 0;
for (var i = 0; i < 15; i++) {
    var theTh = $("#colTh" + i)
    var thWidth = 0;  // in pixel
    thWidth += theTh.width();
    thWidth += parseInt(theTh.css("padding-left"), 10) + parseInt(theTh.css("padding-right"), 10); //Total Padding Width
    thWidth += parseInt(theTh.css("margin-left"), 10) + parseInt(theTh.css("margin-right"), 10); //Total Margin Width
    thWidth += parseInt(theTh.css("borderLeftWidth"), 10) + parseInt(theTh.css("borderRightWidth"), 10); //Total Border Width

    width_total += thWidth;
    console.log("width " + i + ": " + width_total)
}

我在第 7 列的宽度为 1200

我在计算可打印宽度时哪里出错了?

  • 边距/边框/填充/宽度:我认为这应该是正确的
  • DPI 中的页面密度:如果它介于 140 和 150 之间,则可以容纳。有没有办法找出浏览器正在使用什么/设置密度?
  • 还有别的吗?

【问题讨论】:

  • pdfinfo 告诉我生成的 PDF 有 Page size: 595 x 842 pts (A4)。这适合 A4 尺寸 @ 72 DPI。但是它应该在 6 和 7 之间切页 ...
  • 有趣。即使我使用th, td { page-break-inside:avoid; page-break-after:auto; width: 150px;max-width: 150px;min-width:150px;},Firefox 仍然适合一页上的所有列,而 chrome 会在第 7 列之后/之后插入

标签: html printing


【解决方案1】:

我认为答案是

  1. 浏览器调整表格(“缩小以适应”)。用户可以在浏览器打印设置中禁用此功能。
  2. 默认结果为 96 DPI。 210mm 是 A4 页面的宽度,25.4mm/inch => 96 px/inch * (1/25.4) inch/mm * 210mm = 794px。

【讨论】:

    猜你喜欢
    • 2014-12-03
    • 2016-10-23
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 2010-09-06
    • 2019-12-22
    相关资源
    最近更新 更多