Alter the default header/footer when printing to PDF

后端 未结 7 1652
攒了一身酷
攒了一身酷 2020-12-14 02:21

I\'m trying to use Google Chrome as a replacement of PhantomJS to render HTML into PDF. So far it\'s been working well for me. The only issue I have that I have not found an

7条回答
  •  臣服心动
    2020-12-14 02:46

    It is possible to create custom headers and footer by using

    and
    tags. I use this for generating PDF's using Chrome Headless. I have not tested it in Firefox, IE etc...

    Custom Header
    Page Content - as long as you want
    Footer Content

    the CSS

    @page {
      margin: 0;
    }
    @media print {
      footer {
        position: fixed;
        bottom: 0;
      }
      header {
        position: fixed;
        top: 0;
      }
    }
    

    The @page { margin: 0 } removes the default header and footer.

    Hope this helps.

提交回复
热议问题