A4纸网页打印

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>A4纸网页打印</title>
  <!-- 去除页眉页脚 -->
  <style media="print">
    @page {
      /* auto is the initial value */
      size: auto;  
      /* this affects the margin in the printer settings */
      margin: 5mm; 
    }
  </style>
</head>
<!-- 
  在公制长度单位与屏幕分辨率进行换算时,必须用到一个DPI(Dot Per Inch)指标。 
  经过我仔细的测试,发现了网页打印中,默认采用的是96dpi,并非传闻的72dpi 
  A4纸张的尺寸是210×297mm,按1英寸=25.41mm换算,即8.264×11.688英寸 
  所以,A4纸96dpi下的分辨率是794×1123,这就是我们在制作网页的时候需要的象素。 
  但是打印机是无法满幅打印的,总要有页边距,所以我们在制作网页的时候必须减去页边距。

  A4纸的尺寸:210×297mm 
  A3纸的尺寸:297×420mm
 -->
<body>
  <!-- 打印页边距设定为 0mm 时,网页内最大元素的分辨率:794×1123 -->
  <div style="794px;height:1123px;border:1px solid #000000;margin:0 auto;page-break-after:always;"></div>
  <!-- 打印页边距设定为 5mm 时,网页内最大元素的分辨率:756×1086 -->
  <div style="756px;height:1086px;border:1px solid #000000;margin:0 auto;page-break-after:always;"></div>
  <!-- 打印页边距设定为 19.05mm 时,网页内最大元素的分辨率:649×978  -->
  <div style="649px;height:978px;border:1px solid #000000;margin:0 auto;"></div>
</body>
</html>

原文地址:https://www.cnblogs.com/archermeng/p/8587529.html