Header and footer for specific pages in print format

I want to set header and footer in every pages except first and last page in print format.Is it possible? If yes, Please send the code in the comment.

1 Like

@Salmanadayatt Yes, you can add headers and footers to every page except the first and last in an ERPNext/Frappe print format using CSS @page rules with pseudo-classes, as print formats generate PDFs via wkhtmltopdf, which supports them.

Add this to the Custom CSS section of your Print Format (doctype: Print Format, via Customize Form):

@page :first {
  @top-left { content: normal; } /* No header on first page */
  @bottom-right { content: normal; } /* No footer on first page */
}

@page :last {
  @top-left { content: normal; } /* No header on last page */
  @bottom-right { content: normal; } /* No footer on last page */
}

@page {
  @top-left {
    content: "Your Header Content Here"; /* e.g., Company Name, Logo via element */
    font-size: 10pt;
  }
  @bottom-right {
    content: "Page " counter(page) " of " counter(pages); /* Auto page numbering */
    font-size: 8pt;
  }
  margin-top: 20mm; /* Space for header */
  margin-bottom: 20mm; /* Space for footer */
}

Enable Repeat Header and Footer in Print Settings (for letterhead if used) or ensure your HTML has <div id="header-html"> and <div id="footer-html"> with position: running(top-left) or similar for complex content.

its not working