防止在打印网页pdf时打印空白纸张

时间:2020-09-17 09:37:54

标签: javascript html css printing media-queries

我使用@media查询覆盖了网页的CSS属性,并创建了一个对我有利的打印布局。

但是我有一个问题:即使我要在一张A4纸上完全打印“保持”,如果我单击“打印”(无论是打印pdf还是普通纸打印),它也会打印为白色和空白额外的工作表。

如何防止这种情况?

我的代码:

@media print {
           
      .noPrint{
        display: none;
      }

      section{         
        display:block;   
        background-color: white;
        height: 100%;
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        margin:0;
        padding: 1em;  

        /*settings */    
        color-adjust: exact !important;  
        -webkit-print-color-adjust: exact !important;
      }

      a{
        display:none;
      }
      button{
        display:none;
      }
      h1{
        font-size: 3vw;
      }
 }

1 个答案:

答案 0 :(得分:0)

您可以使用:

page-break-after: auto;

或:

@media print {
    html, body {
        height: 99%;    
    }
}

how to avoid extra blank page at end while printing?

中所述

但是,由于我还没有从事印刷工作,因此我无能为力了。