Example 25

Description

PageFrames can be used to define that a header or footer should be printed only on certain pages.
Just add multiple PageFrames with different contents to the header or footer container of the report.
In this example there is header for all pages but not the first page and there are two footers on for odd and one for even pages.
A few manual page breaks has been added to show the effects.

Output

<?php

include_once "../src/Report.php";

use Adi\ReportLib as ReportLib;

// Create report instance
//  default format A4, portrait with margins left = 20mm, top = 10mm, right = 10mm and bottom = 10mm
$report = new ReportLib\Report();
$report->setCountPages(true);

// Get ref to the report body
$body = $report->getBody();
$header = $report->getHeader();
$footer = $report->getFooter();

addHeader($header);
addFooter($footer, ReportLib\PageFrame::C_OnOddPages, 'R');
addFooter($footer, ReportLib\PageFrame::C_OnEvenPages, 'L');

$body->AddPageBreak();
$body->AddPageBreak();

// Produce the output of the report
//  uses the same params as TCPDF (F = File, I = Preview etc.)
$report->output(__DIR__ . "/example_025.pdf", 'I');


function addHeader(ReportLib\SerialFrame $header) : void
{
    $tsBold = ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::BOLD);

    $pf = $header->AddPageFrame(ReportLib\PageFrame::C_OnAllButFirstPage);

    $box = $pf->AddBox();
    $box->setUseFullWidth(true);
    $box->setPadding(1.0);
    $box->setHeight(15.0);
    $box->setBackground("#EEEEEE");

    $hf = $box->AddHContainer();
    $tf = $hf->AddText("Header for all pages but not on the first page.", $tsBold);
}

function addFooter(ReportLib\SerialFrame $footer, int $onPageNr, string $hAlign) : void
{
    $tsNormal = ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::NORMAL);

    $pf = $footer->AddPageFrame($onPageNr);
    $pf->AddHLine(0.3);

    $box = $pf->AddBox();
    $box->setUseFullWidth(true);
    $box->setHeight(10.0);

    $tf = $box->AddText("Page [VAR_PAGE] of [VAR_TOTAL_PAGES]", $tsNormal);
    $tf->setHAlignment($hAlign);
    $tf->setVAlignment('T');
}