TCPDF - How to detect in Header/Footer function if pdf page is in landscape or portrait mode?

Viewed 704

I have a cutom page and header function in my TCPDF file. Since I use a different header/footer for portrait and landscape pages, I want to detect the orientation of the page and use the correct header/footer.

First I was using a switch with "this->page" to indicate which header/footer to use based on the page number. But sometimes the text on page on a portrait page is longer and it adds an additional page and I end up with a mess.

How can I detect if a pdf page is in landcape or portrait mode?

Something like this is what I want to do, if it is possible.

class MYPDF extends TCPDF {
    public function Header() {
        //Detect if the page is on landscape or portrait mode
        $pageOrientation = ????

        if(//page orientation is landscape){
            //use this custom header
        }
        else {
            //use this other custom header
        }        
    }
}

Thanks in advance.

2 Answers

Inside your header & footer you'll have access to the orientation using

$this->CurOrientation

e.g.

if($this->CurOrientation=="L") {
    // code for landscape pages
} else {
    // code for portrait pages
}
Related