如何在同一张A4纸上两次打印网页?

时间:2019-12-15 16:52:27

标签: html css web media-queries

我要在同一张A4纸上打印两个发票副本。反正有实现相同的目标吗?确保发票的单次打印(在我的情况下为html表)不会超过A4纸的一半。

1 个答案:

答案 0 :(得分:0)

如果我正确理解了您的问题,则将需要首先在A4页上打印出2张发票的.html文件准备为.html / .php文件(网页),然后进行打印。
我还要假设,您已经创建了一个动态页面,可将数据提取到发票中。

/** style.css  **/

.invoice {
  margin-top: 2em;
}

span {
  color: blue;
  border: 1px solid black;
}

.extra span {
  color: inherit;
}

@media print {
    body{
        width: 21cm;
        height: 29.7cm;
        margin: 20mm; /* Adjust margin as you like. */        
   } 
   
   * {background: transparent !important; color: black !important; text-shadow: none !important; filter:none !important; -ms-filter: none !important} /* Black prints faster */
   
   pre, blockquote {border: 1px solid #999; page-break-inside: avoid; }


thead {display: table-header-group; } /* Repeat header row at top of each printed page */
  tr, img {page-break-inside: avoid; }
  
  img {max-width: 100% !important; }
  
  @page {margin: 0.5cm}
  
  p, h2, h3 {orphans: 3; widows: 3}
  
  h2, h3{page-break-after: avoid}
}
<!DOCTYPE html>
<html>
<head>

</head>

<body>

<div class="invoice">
  Here is <span>First invoice table format</span>
</div>

<div class="invoice extra" style="color:green">
  Here is <span>Second invoice table format</span>.
</div>

</body>
</html>