Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shawdow's avatar

dompdf adding multiple headers

i have below blade file headers working on each page correctly i need to add multiple headers and break content after adding the new header and footer below blade file i am using dompdf package

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Template</title>
    <link href='https://fonts.googleapis.com/css2?family=Jersey+25+Charted&family=Poetsen+One&display=swap' rel='stylesheet'>
    <style>
        /* Add your styles */
        body {
          font-family: "Jersey 25 Charted", sans-serif;   font-weight: 400;   font-style: normal;
        }
        .header {
            position: fixed;
            top: -40px;
            left: 0;
            right: 0;
            width: 90%;
            background-color: #333;
            color: #fff;
            padding: 10px;
            text-align: center;
        }

        .footer {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: #333;
            color: #fff;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
<body>

  <div class="header">
      <!-- Add header content here -->
      Header Content
    </div>

    <div class="footer">
        <!-- Add footer content here -->
        Footer Content
    </div>

    <h1> TAx Certificate </h1>
    
    <div class="content">
        <!-- Add your main content here -->
        <h1>Hello, PDF!</h1>
        <p>This is your PDF content.</p>
    </div>
    <div class="content">
      <!-- Add your main content here -->
      <h1>Hello, PDF!</h1>
      <p>This is your PDF content.</p>
  </div>
  <div class="content">
    <!-- Add your main content here -->
    <h1>Hello, PDF!</h1>
    <p>This is your PDF content.</p>
</div>
<div class="content">
  <!-- Add your main content here -->
  <h1>Hello, PDF!</h1>
  <p>This is your PDF content.</p>
</div>
<div class="content">
  <!-- Add your main content here -->
  <h1>Hello, PDF!</h1>
  <p>This is your PDF content.</p>
</div>

  <!-- new header need to add here -->

<h1> HOA Certificate </h1>

<div class="content">
  <!-- Add your main content here -->
  <h1>Hello, PDF!</h1>
  <p>This is your PDF content.</p>
</div>
<div class="content">
  <!-- Add your main content here -->
  <h1>Hello, PDF!</h1>
  <p>This is your PDF content.</p>
</div>
</body>
</html>

controller code

// Load HTML content from Blade view
            $html = view('sample-pdf', $request->all())->render();

            // Create new Dompdf instance
            $dompdf = new Dompdf();

            // Load HTML to Dompdf
            $dompdf->loadHtml($html);

            // Set paper size and orientation
            $dompdf->setPaper('A4', 'portrait');

            // Render PDF (optional: you can set additional options here)
            $dompdf->render();

            $font = $dompdf->getFontMetrics()->get_font("helvetica", "bold");
            $dompdf->get_canvas()->page_text(530, 15, "Page {PAGE_NUM} / {PAGE_COUNT}", $font, 10, array(0, 0, 0));

            // Output PDF
            return $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
0 likes
0 replies

Please or to participate in this conversation.