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

Downloads > Add-On

 
         
 

Index

Informations

Author: Min's
License: Freeware

Description

This class prints an index from the created bookmarks. It therefore requires the bookmarks extension.

Source

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

class PDF_Index extends PDF_Bookmark
{
function CreateIndex(){
    //Index title
    $this->SetFontSize(20);
    $this->Cell(0, 5, 'Index', 0, 1, 'C');
    $this->SetFontSize(15);
    $this->Ln(10);

    $size=sizeof($this->outlines);
    $PageCellSize=$this->GetStringWidth('p. '.$this->outlines[$size-1]['p'])+2;
    for ($i=0;$i<$size;$i++){
        //Offset
        $level=$this->outlines[$i]['l'];
        if($level>0)
            $this->Cell($level*8);

        //Caption
        $str=$this->outlines[$i]['t'];
        $strsize=$this->GetStringWidth($str);
        $avail_size=$this->w-$this->lMargin-$this->rMargin-$PageCellSize-($level*8)-4;
        while ($strsize>=$avail_size){
            $str=substr($str, 0, -1);
            $strsize=$this->GetStringWidth($str);
        }
        $this->Cell($strsize+2, $this->FontSize+2, $str);

        //Filling dots
        $w=$this->w-$this->lMargin-$this->rMargin-$PageCellSize-($level*8)-($strsize+2);
        $nb=$w/$this->GetStringWidth('.');
        $dots=str_repeat('.', $nb);
        $this->Cell($w, $this->FontSize+2, $dots, 0, 0, 'R');

        //Page number
        $this->Cell($PageCellSize, $this->FontSize+2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R');
    }
}
}
?>

Example

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

$pdf=new PDF_Index();
$pdf->Open();
$pdf->SetFont('Arial', '', 15);

//Page 1
$pdf->AddPage();
$pdf->Bookmark('Section 1');
$pdf->Cell(0, 6, 'Section 1', 0, 1);
$pdf->Bookmark('Subsection 1', 1, -1);
$pdf->Cell(0, 6, 'Subsection 1');
$pdf->Ln(50);
$pdf->Bookmark('Subsection 2', 1, -1);
$pdf->Cell(0, 6, 'Subsection 2');

//Page 2
$pdf->AddPage();
$pdf->Bookmark('Section 2');
$pdf->Cell(0, 6, 'Section 2', 0, 1);
$pdf->Bookmark('Subsection 1', 1, -1);
$pdf->Cell(0, 6, 'Subsection 1');

//Index
$pdf->AddPage();
$pdf->Bookmark('Index');
$pdf->CreateIndex();
$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.