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

luismabenitez's avatar

DomPDF & html header / footer show and hide

Working on a creating a self generated magazine on PDF, where basically I have two type of pages, full image pages and content pages.

The full image pages doesn't need to have the header or the footer so trying to find the way to show / hide the header and the footer in the pages I want. Was trying with z-index, what is a basic concept and sounds like it should to work, but dompdf doesn't like it.

I have defined the css for this two type of pages, the full images as absolute and the other as relative.

.cover_sheet {
    position         : absolute;
    top              : 0px;
    left             : 0px;
    right            : 0px;
    bottom           : 0px;
    overflow         : hidden;
    margin           : 0;
    padding          : 0;
}

.margin_sheet {
    position         : relative;
    top              : 70px !important;
    bottom           : 0px;
    overflow         : auto;
    margin           : 40px !important;
    padding          : 0;
}

Then, I'm defining every block with:

div.page {
    page-break-after: always;
    page-break-inside: auto;
}

I need to have it as and because I have blocks with more than one page. I already make it works just having divs for every page with like "" and setting the .margin_sheet as absolute, but then, if the first page on the block overflows, it doesn't show the content of next pages.

So with the solution I have everything works as I expected, but just need to hide the damn header on footer on the "cover_sheet" divs. Any idea?

0 likes
4 replies
Davieboy's avatar

hey @luismabenitez i ended up going with Eliby/TCPDF https://github.com/elibyy/tcpdf-laravel as i just couldnt get other PDF packages to do exactly what i wanted it to do, ideally id of preferred TCPDF like my last php 5.6 project but unfortunately its not compatible yet.

Good thing is the most of the TCPDF examples all work with Eliby version https://tcpdf.org/examples/example_051/

Might be an option for you if you cant get it doing what you want it to.

luismabenitez's avatar

thanks @davieboy , but as it says, TCPDF has no php7 support. So i guess I should to be kicking my head against DomPDF for now.

Davieboy's avatar

true @luismabenitez , working fine on php8 for what i need it but that's really just images on a page and displaying info from the db in a basic layout, just thought it was worth a mention.

Good Luck, hope you get it sorted

1 like
luismabenitez's avatar

yeah I appreciate. Will try to fix with dompdf just because I'm using it in the whole system. If not I will give a change to see if it works. Thanks again.

Please or to participate in this conversation.