【问题标题】:Prevent to print white empty sheets while printing pdf of a webpage打印网页的pdf时防止打印白色空白纸
【发布时间】:2021-01-04 04:24:24
【问题描述】:

我使用@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;
      }
 }

【问题讨论】:

    标签: javascript html css printing media-queries


    【解决方案1】:

    你可以使用:

    page-break-after: auto;
    

    或:

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

    how to avoid extra blank page at end while printing?中所述

    但由于我没有那么多时间使用打印,所以我无能为力了。

    【讨论】:

    • @margotdb 您是否也查看了链接,那里有一个示例可能对您有所帮助。
    • 我刚刚尝试了链接中的所有解决方案,但没有任何效果
    • 问题已解决:我在 @media print 中覆盖了 :host(我的 lit-element 类扩展了另一个类)
    • @margotdb 不错。玩得开心编码。
    猜你喜欢
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多