There is an invoice preview webpage. I want to set header and footer information off while printing it. I know we can edit the page setup settings. But I wanted to know if we can do something without changing the default page setup settings. With default setting inside page setup, webpage title and webpage path are displayed for header and footer respectively.

Thanks

Dani AI

Generated

— for a printable invoice that must not show the browser title/path lines, the only dependable approach is to stop relying on the browser's print dialog: produce a print-ready PDF (or a server-rendered print file) and give that to the user. correctly flagged that browser print behavior is controlled on the client; below are safe, practical options and short examples you can apply immediately.

  1. Server-side PDF (recommended for invoices)
  • Render your invoice HTML on the server and convert it to PDF so the PDF output contains exactly what you want (no UA headers/footers). Libraries/tools: Dompdf (pure PHP), wkhtmltopdf (WebKit-based), or headless Chrome/Puppeteer. This guarantees consistent results across users and avoids asking users to change browser print settings.
  1. Server-side render examples
  • Dompdf (PHP) quick flow:

    require 'vendor/autoload.php';
    use Dompdf\Dompdf;
    $dompdf = new Dompdf();
    $dompdf->loadHtml($html);
    $dompdf->setPaper('A4');
    $dompdf->render();
    $dompdf->stream('invoice.pdf', ['Attachment' => false]);
  • wkhtmltopdf (CLI) example:

    wkhtmltopdf --print-media-type --margin-top 0 --margin-bottom 0 input.html output.pdf
  1. Client-side print stylesheet (limited)
  • Use a focused @media print stylesheet to hide UI and lay out the invoice for printing, and add @page to control margins. This helps appearance but does not reliably remove browser-added headers/footers — those remain a user/UA setting.

References and tools

Notes: generating a PDF server-side is slightly more work but it is the only way to ensure every recipient gets an invoice without browser headers/footers, and it scales well if you need attachments, signed PDFs, or archival copies.

Recommended Answers

All 2 Replies

To my knowledge changing the page print settings for when a user prints a page is done by javascript and css as it is client side. There isn't much that php can do to change the page printout settings other then echoing the javascript/css code.

Thanks for the note..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.