How to use HTML to print header and footer on every printed page of a document?

前端 未结 20 1712
迷失自我
迷失自我 2020-11-21 16:51

Is it possible to print HTML pages with custom headers and footers on each printed page?

I\'d like to add the word \"UNCLASSIFIED\" in Red, Arial, size 16pt to the t

20条回答
  •  深忆病人
    2020-11-21 17:23

    If you are using a template engine like Asp.net Razor Engine or Angular, I think you must re-generate your page and split the page in several pages and then you can freely markup each page and put header and footer on theme. one example could be as bellow:

    @page {
      size: A4;  
       margin: .9cm;
    }
    
    
    @media print {
    
       body.print-paper-a4 {
        width: 210mm;
        height: 297mm;
      }
    
       body {
           background: white;
           margin: 0;
           padding: 0;
       }
    
       .print-stage,
       .no-print {
           display: none;
       }
    
    
       body.print-paper.a4 .print-paper {
          width: 210mm;
            height: 297mm;
        }
    
       .print-paper {
           page-break-after: always;
           margin: 0;
           padding: .8cm;
           border:none;
           overflow: hidden;
       }
    
    }
    
    
    
    
    
    .print-papers {
        display: block;
        z-index: 2000;
        margin: auto;
    
    }
    
    
    body.print-paper-a4 .print-paper {
        width: 21cm;
        height:27cm;
    }
    
    
    .print-paper {
        margin: auto;
        background: white;
        border: 1px dotted black;
        box-sizing: border-box;
        margin: 1cm auto;
        padding: .8cm;
           overflow: hidden;   
    }
    
    
    body.print-mode .no-print-preview {
        display: none;
    }
    
    body.print-mode .print-preview {
        display: block;
    }
    
            
            
      

提交回复
热议问题