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

lilo's avatar
Level 2

Adding cover page with dompdf

Hello,

I transform my view blade to pdf. I want to add a cover page as first page and an end page as last page. The content of these pages will be photo. How can I add first and last page in my pdf?

Here is my controller:

$analysisReports = $this->get_customer_data($id);
    foreach($analysisReports as $analysisReport)
    {
        $output = '
            
            <html>
                <head>
                  <style>
                    @page { margin: 180px 50px; }
                    #header { position: fixed; left: 0px; top: -150px; right: 0px; height: 100px;  text-align: center; }
                    #footer { position: fixed; left: 0px; bottom: -150px; right: 0px; height: 100px; }
                   
                  </style>
                </head>  
                <body>
                  
                  <div id="header">
                    <img src="./pdf-header.jpg" width="700px" height="100px">
                  </div>
                  <div id="footer">
                    <img src="./pdf-footer.jpg" width="700px" height="100px">                        
                  </div>
                  <div id="content">
                       
                            <p style="text-align:left;font-family: DejaVu Serif;font-size: 12px"><strong>Costumer:</strong> '.$analysisReport->costumer->firm_name.'<span style="float:right;"><strong>Report No:</strong> '.$analysisReport->report_no.'</span></p>
                            <p style="text-align:left;font-family: DejaVu Serif;font-size: 12px"><strong>Related Person:</strong> '.$analysisReport->related_person->name.'<span style="float:right;"><strong>Report Date:</strong> '.$analysisReport->report_date.'</span></p>
                            <p style="text-align:right;font-family: DejaVu Serif;font-size: 12px"><strong>Sample Date Received:</strong> '.$analysisReport->date_received.'</span></p>
                            <h3 align="center" style="font-size: 20px;font-family: DejaVu Serif;">Analysis Report<br></h3>
                            <p style="text-align:left;font-family: DejaVu Serif;font-size: 12px"><strong>Sample Name</strong><br>'.$analysisReport->sample_name->sample_name.'</p>
                        </div>
                            <table width="100%" style="border-collapse: collapse; border: 0px;font-family: DejaVu Serif;font-size: 9px">
                            <tr><th style="border: 1px solid; padding:10px;font-size: 12px" width="70%">Cations-Metals </th><td colspan="6" style="border: 1px solid; padding:10px;text-align:right;font-size: 12px">Result / Sonuç</td><td colspan="1" style="border: 1px solid; padding:10px;text-align:right;font-size: 12px">Unit/Birim</td></tr>
                            <tr bgcolor="lightblue"><th style="border: 1px solid; padding:5px;" width="35%">Aluminum (Al)</th><td colspan="6" style="border: 1px solid; padding:5px;text-align:right">'.$analysisReport->aluminum.'</td><td colspan="1" style="border: 1px solid; padding:5px;text-align:right;font-size: 10px">mg/L</td></tr>
                           ...
                            </tr>
		</div>
                </body>
            </html>

        ';
    }
    $output .= '</table>';
    return $output;
0 likes
0 replies

Please or to participate in this conversation.