Custom TCPDF Header on Page 1

Hi Experts,

Using TCPDF, I'm trying to have one header on page 1, and another on all subsequent pages, as per my Liners 17-24, but this is not happening, can anyone see why?

<?php
//Temporarily Change directory to TCPDF to load files...
    $currentDIR = getcwd();
    chdir("../tcpdf/examples");
    require_once('tcpdf_include.php');

    //Change DIR back
    chdir($currentDIR);

class MYPDF extends TCPDF {

	//Page header
	public function Header() {
		// Title
                $this->Ln();
                
                $page = $this->getAliasNumPage();
                if ($page == 1){
                    $this->Cell(0, 15, 'Page 1', 0, false, 'C', 0, '', 0, false, 'M', 'M');
                    $this->Ln();
                } else {
                    $header = $page . '<< TCPDF Example 003 >>';
                    $this->Cell(0, 15, $header, 0, false, 'C', 0, '', 0, false, 'M', 'M');
                }
	}

	// Page footer
	public function Footer() {
		// Position at 15 mm from bottom
		$this->SetY(-15);
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
	}
}

    $pdf = new MYPDF('L', 'mm', array(215.9, 279.4));
        $pdf->SetTitle('Manifest');
        $pdf->SetMargins(5, 5);
        $pdf->SetAutoPageBreak(TRUE);
        $pdf->SetPrintHeader(TRUE);
        $pdf->SetHeaderMargin(10);
            $pdf->SetFont('Helvetica', '', 9);
            $pdf->AddPage();
            $pdf->AddPage();
            $pdf->AddPage();
            
             $file = 'Manifest.pdf';
      $pdf->Output($file); 
?>

Open in new window


Any help will be appreciated.
APD TorontoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Check these links.
http://www.tcpdf.org/doc/code/classTCPDF.html#ae11c5f52caa0df8609ec22c30cd54055
http://www.tcpdf.org/doc/code/classTCPDF.html#aa6e5b824889f7c484cc76ce1c134e2ed
I put in a var_dump() to see what was in the variable.   You can take that out, now that we know which function to call.
http://iconoun.com/demo/temp_apd_toronto.php
<?php // demo/temp_apd_toronto.php

/**
 * http://www.experts-exchange.com/questions/28704340/Custom-TCPDF-Header-on-Page-1.html
 */
error_reporting(E_ALL);

// A DATE SETTING MAY BE REQUIRED - DEPENDS ON PHP INSTALLATION SETTINGS
date_default_timezone_set('America/Chicago');

// SYNTHESIZE THE PDF FILE URL AND FILE NAME
$pdf_file_link    = 'storage/temp_apd_toronto.pdf';
$pdf_file_name    = getcwd() . DIRECTORY_SEPARATOR . $pdf_file_link;

// LOAD THE TCPDF CLASS AND CONFIGURATION
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

// EXTEND THE TCPDF OBJECT SO WE CAN SUBSTITUTE OUR OWN METHODS
class MYPDF extends TCPDF
{
	public function Header()
	{
        $this->Ln();

        // THIS GETS AN ALIAS NAME
        $page = $this->getAliasNumPage();

        // THIS GETS A PAGE NUMBER
        $page = $this->getPage();

        // ACTIVATE THIS TO SEE WHAT IS IN THE VARIABLE
        // var_dump($page);

        if ($page == 1)
        {
            $this->Cell(0, 15, 'Page 1', 0, false, 'C', 0, '', 0, false, 'M', 'M');
            $this->Ln();
        }
        else
        {
            $header = $page . '<< TCPDF Example 003 >>';
            $this->Cell(0, 15, $header, 0, false, 'C', 0, '', 0, false, 'M', 'M');
        }
	}

	public function Footer()
	{
		// Position at 15 mm from bottom
		$this->SetY(-15);
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
	}
}


$pdf = new MYPDF('L', 'mm', array(215.9, 279.4));
$pdf->SetTitle('Manifest');
$pdf->SetMargins(5, 5);
$pdf->SetAutoPageBreak(TRUE);
$pdf->SetPrintHeader(TRUE);
$pdf->SetHeaderMargin(10);
$pdf->SetFont('Helvetica', '', 9);
$pdf->AddPage();
$pdf->AddPage();
$pdf->AddPage();

// WRITE THE PDF FILE TO THE SERVER
$pdf->Output($pdf_file_name, 'F');

// PRESENT A CLICKABLE LINK SO WE CAN D/L AND PRINT THE PDF
echo '<a target="my_PDF" href="' . $pdf_file_link . '"><strong>Print the PDF</strong></a>';

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
APD TorontoAuthor Commented:
Thanks Ray!
0
Ray PaseurCommented:
Thanks for the points and thanks for using E-E.  Var_dump() is always our friend!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.