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

lilo's avatar
Level 2

Remove header and footer from the last page of pdf using css

Hi, I'm using laravel dompdf and I have a cover page that is generated at the end of my pdf. But I don't want header and footer to appear on the last page.

Here is my code:

$output='<html><body>
		     <div class="firstpage">
                            <img src="...">
                         </div>
                         <div id="header">
                            <img src="..." width="700px" height="104px">
                          </div>                          
             	      <div id="content">';
            $output .= '
                <html>
                    <head>
                      <style>
                        @page { margin: 180px 60px;}
                        #header { position: fixed; left: 0px; top: -150px; right: 0px; height: 100px;  text-align: center; }
                        #footer{ position: fixed; left: -20px; bottom: -150px; right: 0px; height: 100px; }
                        .firstpage {
                            page-break-after: always;
                        }
                        .lastpage{
			//Which css attribute can I have here to remove header and footer?
                         }
                      </style>
                    </head>
                    <body>
                   		<div id="content">

                      	 ......
                    	</div>  
                  
                    </body>   
                </html>

        $output .= '<div id="footer">       
                        		<img src="...." width="700px" height="104px">        
                   		</div>';

    $output .= '       
                 <div class="lastpage">
		// I want to remove the header and footer from this page
                    <img src="..." height="740px" width="521px">
                 </div>
                </body>
                
                </html>';
    return $output;

All the pages except the first page has header and footer in it. But I want to remove them from the div which has "lastpage" as class. How can I do it using css? Thanks in advance

0 likes
6 replies
lilo's avatar
Level 2

Would it be better? And is it impossible to remove header and footer in this state? @michaloravec

MichalOravec's avatar

Yes, it would be better. You don't have to concat a string there.

lilo's avatar
Level 2

Anyone have any other ideas about this?

Please or to participate in this conversation.