 |
 |
|
|
 |
| |
 |
Downloads > Add-On |
 |
|
 |
| |
|
|
|
|
| |
Reference index
InformationsAuthor: Pierre-André Vullioud License: Freeware
DescriptionThis script allows to display an index with a list of references on several columns.
Reference($txt): adds a reference to the current page.
CreateReference($NbCol): displays the reference list on several columns.
Source
<?php require('fpdf.php');
class PDF_Ref extends FPDF { var $RefActive=0; //Flag indicating that the index is being processed var $ChangePage=0; //Flag indicating that a page break has occurred var $Reference=array(); //Array containing the references var $col=0; //Current column number var $NbCol; //Total number of columns var $y0; //Top ordinate of columns
function Header() { if($this->RefActive==1) { //Title of index pages $this->SetFont('Arial', '', 15); $this->Cell(0, 5, 'Index', 0, 1, 'C'); $this->Ln(); } }
function Reference($txt) { $Present=0; $size=sizeof($this->Reference);
//Search the reference in the array for ($i=0;$i<$size;$i++){ if ($this->Reference[$i]['t']==$txt){ $Present=1; $this->Reference[$i]['p'].=', '.$this->PageNo(); } }
//If not found, add it if ($Present==0) $this->Reference[]=array('t'=>$txt, 'p'=>$this->PageNo()); }
function CreateReference($NbCol) { //Initialization $this->RefActive=1; $this->SetFontSize(8);
//New page $this->AddPage();
//Save the ordinate $this->y0=$this->GetY(); $this->NbCol=$NbCol; $size=sizeof($this->Reference); $PageWidth=$this->w-$this->lMargin-$this->rMargin;
for ($i=0;$i<$size;$i++){
//Handles page break and new position if ($this->ChangePage==1) { $this->ChangePage=0; $this->y0=$this->GetY()-$this->FontSize-1; }
//LibellLabel $str=$this->Reference[$i]['t']; $strsize=$this->GetStringWidth($str); $this->Cell($strsize+2, $this->FontSize+2, $str, 0, 0, 'R');
//Dots //Computes the widths $ColWidth = ($PageWidth/$NbCol)-2; $w=$ColWidth-$this->GetStringWidth($this->Reference[$i]['p'])-($strsize+4); if ($w<15) $w=15; $nb=$w/$this->GetStringWidth('.'); $dots=str_repeat('.', $nb-2); $this->Cell($w, $this->FontSize+2, $dots, 0, 0, 'L');
//Page number $Largeur=$ColWidth-$strsize-$w; $this->MultiCell($Largeur, $this->FontSize+1, $this->Reference[$i]['p'], 0, 1, 'R'); } $this->RefActive==0; }
function SetCol($col) { //Set position on a column $this->col=$col; $x=$this->rMargin+$col*($this->w-$this->rMargin-$this->rMargin)/$this->NbCol; $this->SetLeftMargin($x); $this->SetX($x); }
function AcceptPageBreak() { if ($this->RefActive==1) { if($this->col<$this->NbCol-1) { //Go to the next column $this->SetCol($this->col+1); $this->SetY($this->y0); //Stay on the page return false; } else { //Go back to the first column $this->SetCol(0); $this->ChangePage=1; //Page break return true; } } else { return true; } } } ?>
|
Example
<?php define('FPDF_FONTPATH', 'font/'); require('ref_index.php');
//Sort function for references //To be defined by the user to achieve desired results //This function is case insensitive function cmp ($a, $b) { return strnatcmp(strtolower($a['t']), strtolower($b['t'])); }
$pdf=new PDF_Ref(); $pdf->Open(); $pdf->SetFont('Arial', '', 15);
//Page 1 $pdf->AddPage(); $pdf->Cell(0, 5, 'Page 1', 0, 1, 'C'); $pdf->Reference('Ref1'); $pdf->Reference('Ref90'); $pdf->Reference('A');
//Page 2 $pdf->AddPage(); $pdf->Cell(0, 5, 'Page 2', 0, 1, 'C'); $pdf->Reference('Ref90'); $pdf->Reference('a'); $pdf->Reference('A'); $pdf->Reference('g'); $pdf->Reference('G'); $pdf->Reference('Nom'); for ($i=1;$i<=350;$i++) $pdf->Reference('test'.$i);
//Alphabetic sort of the references usort($pdf->Reference, 'cmp');
//Creation of index $pdf->CreateReference(4); $pdf->Output(); ?>
|
View the result here.
DownloadZIP | TGZ
| | |