如何计算切割表的位置?

时间:2017-08-31 08:19:39

标签: html printing

我已经生成了一个带有https://gist.github.com/MartinThoma/056183bc0862a787a8d4e8fe57e51f3f

大表的简单HTML页面

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

Google Chrome PDF打印插件会在第7列中删除页面:

enter image description here

但是当我用

计算宽度时
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之间,它可以适合。有没有办法找出浏览器正在使用/设置密度?
  • 别的什么?

1 个答案:

答案 0 :(得分:0)

我认为答案是

  1. 浏览器调整表格(“缩小到适合”)。用户可以在浏览器打印设置中禁用此功能。
  2. 默认结果为96 DPI。 210mm是A4页面的宽度,25.4mm /英寸=> 96像素/英寸*(1 / 25.4)英寸/毫米* 210毫米= 794像素。
相关问题