I don’t always want headers in my PDF

We have an online quotation tool on our website for producing on the fly quotations for telephone systems and IP PBX’s. To generate these quotations we use a combination of PHP and FPDF to create PDF’s. I decided to add a header to each page which looked great, but when you import pages from another PDF these are not always convenient and sometimes creates a mess at the top of the pages. The header is created each time you addpage() and there seem to be no way to switch them on or off when needed.

So I decided to go hacking around FPDF to add a switch in the addpage() script. Anyway I am not a great coder, got scared and decided on trying to work out a KISS solution to my problem. After 10 minutes of thought this is what I came up with and it seems to work.

$headerswitch = ‘Y’;

class PDF extends FPDI
{
//Page header
function Header()
{
global $company;
global $headerswitch;

if($headerswitch == ‘Y’){
$this->SetXY(0,0);
$this->SetLeftMargin(0);
$this->SetFont(’Arial’,’B’,16);
$this->SetFillColor(197,148,148);
$this->Cell(210,3,”,0,1,C,1);
$this->SetFillColor(174,30,35);
$this->SetTextColor(255,255,255);
$this->Cell(210,8,’Online Proposal for ‘.$company,0,1,C,1);
$this->SetFillColor(160,160,160);
$this->Cell(210,3,”,0,1,C,1);
$this->Ln(20);
$this->SetLeftMargin(10);}
else
{}

}

}

$pdf=new pdf();
$pdf->AddPage();
$pdf->Cell(189,10,’Hello World with Header’,0,1);

$headerswitch = ‘N’;
$pdf->addPage();
$pdf->Cell(189,10,’Hello World No Header’,0,1);

I thought I would just let you guys know, who are not great at working these things out, as Google did not answer my question

Leave a Reply

You must be logged in to post a comment.