fpdf
PHP powered
home was ist fpdf? downloads & add-ons dokumentation faq forum impressum links kontakt
 

Downloads > Add-On

 
         
 

Page groups

Informations

Author: Larry Stanbery
License: Freeware

Description

This script allows to do page numbering inside groups, such as: 1/2, 2/2, then back to 1/4, 2/4...

Source

<?php
require('fpdf.php');

// Written by Larry Stanbery - 20 May 2004
// "freeware" -- same license as FPDF
// creates "page groups" -- groups of pages with page numbering
// total page numbers are represented by aliases of the form {nbX}

class PDF_PageGroup extends FPDF
{
    var $NewPageGroup;   // variable indicating whether a new group was requested
    var $PageGroups;     // variable containing the number of pages of the groups
    var $CurrPageGroup;  // variable containing the alias of the current page group

    // create a new page group; call this before calling AddPage()
    function StartPageGroup()
    {
        $this->NewPageGroup=true;
    }

    // current page in the group
    function GroupPageNo()
    {
        return $this->PageGroups[$this->CurrPageGroup];
    }

    // alias of the current page group -- will be replaced by the total number of pages in this group
    function PageGroupAlias()
    {
        return $this->CurrPageGroup;
    }

    function _beginpage($orientation)
    {
        parent::_beginpage($orientation);
        if($this->NewPageGroup)
        {
            // start a new group
            $n = sizeof($this->PageGroups)+1;
            $alias = "{nb$n}";
            $this->PageGroups[$alias] = 1;
            $this->CurrPageGroup = $alias;
            $this->NewPageGroup=false;
        }
        elseif($this->CurrPageGroup)
            $this->PageGroups[$this->CurrPageGroup]++;
    }

    function _putpages()
    {
        $nb = $this->page;
        if (!empty($this->PageGroups))
        {
            // do page number replacement
            foreach ($this->PageGroups as $k => $v)
            {
                for ($n = 1; $n <= $nb; $n++)
                {
                    $this->pages[$n]=str_replace($k, $v, $this->pages[$n]);
                }
            }
        }
        parent::_putpages();
    }
}
?>

Example

<?php
define
('FPDF_FONTPATH', 'font/');
require(
'pagegroup.php');

class
PDF extends PDF_PageGroup
{
function
Footer()
{
    $this->SetY(-20);
    $this->Cell(0, 6, 'Page '.$this->GroupPageNo().'/'.$this->PageGroupAlias(), 0, 0, 'C');
}
}

$pdf = new PDF();
$pdf->SetFont('Arial', '', 12);

$pdf->StartPageGroup();
$pdf->AddPage();
$pdf->Write(5, 'Start of group 1');
$pdf->AddPage();

$pdf->StartPageGroup();
$pdf->AddPage();
$pdf->Write(5, 'Start of group 2');
$pdf->AddPage();
$pdf->AddPage();
$pdf->AddPage();

$pdf->Output();
?>

View the result here.

Download

ZIP | TGZ
 






 
         
         
 
 
fpdf.de © Copyright 2004-2006 carrib internet solutions - Beachten Sie bitte die Nutzungsbedingungen
Eine Verwendung der auf fpdf.de befindlichen Inhalte (Texte, Grafiken) ist nur mit Zustimmung des Betreibers zulässig.