Public Member Functions | Data Fields

PDF Class Reference

Inheritance diagram for PDF:
Inheritance graph
[legend]

Public Member Functions

 Header ()
 Footer ()
 Header ()
 Footer ()
 ChapterTitle ($num, $label)
 ChapterBody ($file)
 PrintChapter ($num, $title, $file)
 Header ()
 Footer ()
 SetCol ($col)
 AcceptPageBreak ()
 ChapterTitle ($num, $label)
 ChapterBody ($file)
 PrintChapter ($num, $title, $file)
 LoadData ($file)
 BasicTable ($header, $data)
 ImprovedTable ($header, $data)
 FancyTable ($header, $data)
 PDF ($orientation='P', $unit='mm', $format='A4')
 WriteHTML ($html)
 OpenTag ($tag, $attr)
 CloseTag ($tag)
 SetStyle ($tag, $enable)
 PutLink ($URL, $txt)

Data Fields

 $col = 0
 $y0
 $B
 $I
 $U
 $HREF

Detailed Description

Definition at line 4 of file tuto2.php.


Member Function Documentation

AcceptPageBreak (  ) 

Reimplemented from FPDF.

Definition at line 47 of file tuto4.php.

References SetCol(), and FPDF::SetY().

{
    //Method accepting or not automatic page break
    if($this->col<2)
    {
        //Go to next column
        $this->SetCol($this->col+1);
        //Set ordinate to top
        $this->SetY($this->y0);
        //Keep on page
        return false;
    }
    else
    {
        //Go back to first column
        $this->SetCol(0);
        //Page break
        return true;
    }
}

BasicTable ( header,
data 
)

Definition at line 18 of file tuto5.php.

References $col, $data, $header, FPDF::Cell(), and FPDF::Ln().

{
    //Header
    foreach($header as $col)
        $this->Cell(40,7,$col,1);
    $this->Ln();
    //Data
    foreach($data as $row)
    {
        foreach($row as $col)
            $this->Cell(40,6,$col,1);
        $this->Ln();
    }
}

ChapterBody ( file  ) 

Definition at line 51 of file tuto3.php.

References $file, FPDF::Cell(), FPDF::Ln(), FPDF::MultiCell(), and FPDF::SetFont().

Referenced by PrintChapter().

{
    //Read text file
    $f=fopen($file,'r');
    $txt=fread($f,filesize($file));
    fclose($f);
    //Times 12
    $this->SetFont('Times','',12);
    //Output justified text
    $this->MultiCell(0,5,$txt);
    //Line break
    $this->Ln();
    //Mention in italics
    $this->SetFont('','I');
    $this->Cell(0,5,'(end of excerpt)');
}

ChapterBody ( file  ) 

Definition at line 79 of file tuto4.php.

References $file, FPDF::Cell(), FPDF::Ln(), FPDF::MultiCell(), SetCol(), and FPDF::SetFont().

{
    //Read text file
    $f=fopen($file,'r');
    $txt=fread($f,filesize($file));
    fclose($f);
    //Font
    $this->SetFont('Times','',12);
    //Output text in a 6 cm width column
    $this->MultiCell(60,5,$txt);
    $this->Ln();
    //Mention
    $this->SetFont('','I');
    $this->Cell(0,5,'(end of excerpt)');
    //Go back to first column
    $this->SetCol(0);
}

ChapterTitle ( num,
label 
)

Definition at line 39 of file tuto3.php.

References FPDF::Cell(), FPDF::Ln(), FPDF::SetFillColor(), and FPDF::SetFont().

Referenced by PrintChapter().

{
    //Arial 12
    $this->SetFont('Arial','',12);
    //Background color
    $this->SetFillColor(200,220,255);
    //Title
    $this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
    //Line break
    $this->Ln(4);
}

ChapterTitle ( num,
label 
)

Definition at line 68 of file tuto4.php.

References FPDF::Cell(), FPDF::GetY(), FPDF::Ln(), FPDF::SetFillColor(), and FPDF::SetFont().

{
    //Title
    $this->SetFont('Arial','',12);
    $this->SetFillColor(200,220,255);
    $this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
    $this->Ln(4);
    //Save ordinate
    $this->y0=$this->GetY();
}

CloseTag ( tag  ) 

Definition at line 70 of file tuto6.php.

References SetStyle().

Referenced by WriteHTML().

{
    //Closing tag
    if($tag=='B' || $tag=='I' || $tag=='U')
        $this->SetStyle($tag,false);
    if($tag=='A')
        $this->HREF='';
}

FancyTable ( header,
data 
)

Definition at line 56 of file tuto5.php.

References $data, $header, $i, FPDF::$w, FPDF::Cell(), FPDF::Ln(), FPDF::SetDrawColor(), FPDF::SetFillColor(), FPDF::SetFont(), FPDF::SetLineWidth(), and FPDF::SetTextColor().

{
    //Colors, line width and bold font
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
    //Header
    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
    //Data
    $fill=false;
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
        $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
        $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
        $this->Ln();
        $fill=!$fill;
    }
    $this->Cell(array_sum($w),0,'','T');
}

Footer (  ) 

Reimplemented from FPDF.

Definition at line 29 of file tuto4.php.

References FPDF::Cell(), FPDF::PageNo(), FPDF::SetFont(), FPDF::SetTextColor(), and FPDF::SetY().

{
    //Page footer
    $this->SetY(-15);
    $this->SetFont('Arial','I',8);
    $this->SetTextColor(128);
    $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}

Footer (  ) 

Reimplemented from FPDF.

Definition at line 22 of file tuto2.php.

References FPDF::Cell(), FPDF::PageNo(), FPDF::SetFont(), and FPDF::SetY().

{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}

Footer (  ) 

Reimplemented from FPDF.

Definition at line 27 of file tuto3.php.

References FPDF::Cell(), FPDF::PageNo(), FPDF::SetFont(), FPDF::SetTextColor(), and FPDF::SetY().

{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Text color in gray
    $this->SetTextColor(128);
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}

Header (  ) 

Reimplemented from FPDF.

Definition at line 11 of file tuto4.php.

References FPDF::$title, FPDF::$w, FPDF::Cell(), FPDF::GetStringWidth(), FPDF::GetY(), FPDF::Ln(), FPDF::SetDrawColor(), FPDF::SetFillColor(), FPDF::SetFont(), FPDF::SetLineWidth(), FPDF::SetTextColor(), and FPDF::SetX().

{
    //Page header
    global $title;

    $this->SetFont('Arial','B',15);
    $w=$this->GetStringWidth($title)+6;
    $this->SetX((210-$w)/2);
    $this->SetDrawColor(0,80,180);
    $this->SetFillColor(230,230,0);
    $this->SetTextColor(220,50,50);
    $this->SetLineWidth(1);
    $this->Cell($w,9,$title,1,1,'C',true);
    $this->Ln(10);
    //Save ordinate
    $this->y0=$this->GetY();
}

Header (  ) 

Reimplemented from FPDF.

Definition at line 7 of file tuto2.php.

References FPDF::Cell(), FPDF::Image(), FPDF::Ln(), and FPDF::SetFont().

{
    //Logo
    $this->Image('logo_pb.png',10,8,33);
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(80);
    //Title
    $this->Cell(30,10,'Title',1,0,'C');
    //Line break
    $this->Ln(20);
}

Header (  ) 

Reimplemented from FPDF.

Definition at line 6 of file tuto3.php.

References FPDF::$title, FPDF::$w, FPDF::Cell(), FPDF::GetStringWidth(), FPDF::Ln(), FPDF::SetDrawColor(), FPDF::SetFillColor(), FPDF::SetFont(), FPDF::SetLineWidth(), FPDF::SetTextColor(), and FPDF::SetX().

{
    global $title;

    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Calculate width of title and position
    $w=$this->GetStringWidth($title)+6;
    $this->SetX((210-$w)/2);
    //Colors of frame, background and text
    $this->SetDrawColor(0,80,180);
    $this->SetFillColor(230,230,0);
    $this->SetTextColor(220,50,50);
    //Thickness of frame (1 mm)
    $this->SetLineWidth(1);
    //Title
    $this->Cell($w,9,$title,1,1,'C',true);
    //Line break
    $this->Ln(10);
}

ImprovedTable ( header,
data 
)

Definition at line 34 of file tuto5.php.

References $data, $header, $i, FPDF::$w, FPDF::Cell(), and FPDF::Ln().

{
    //Column widths
    $w=array(40,35,40,45);
    //Header
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C');
    $this->Ln();
    //Data
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR');
        $this->Cell($w[1],6,$row[1],'LR');
        $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
        $this->Ln();
    }
    //Closure line
    $this->Cell(array_sum($w),0,'','T');
}

LoadData ( file  ) 

Definition at line 7 of file tuto5.php.

References $data, and $file.

{
    //Read file lines
    $lines=file($file);
    $data=array();
    foreach($lines as $line)
        $data[]=explode(';',chop($line));
    return $data;
}

OpenTag ( tag,
attr 
)

Definition at line 59 of file tuto6.php.

References FPDF::Ln(), and SetStyle().

Referenced by WriteHTML().

{
    //Opening tag
    if($tag=='B' || $tag=='I' || $tag=='U')
        $this->SetStyle($tag,true);
    if($tag=='A')
        $this->HREF=$attr['HREF'];
    if($tag=='BR')
        $this->Ln(5);
}

PDF ( orientation = 'P',
unit = 'mm',
format = 'A4' 
)

Definition at line 11 of file tuto6.php.

References FPDF::FPDF().

{
    //Call parent constructor
    $this->FPDF($orientation,$unit,$format);
    //Initialization
    $this->B=0;
    $this->I=0;
    $this->U=0;
    $this->HREF='';
}

PrintChapter ( num,
title,
file 
)

Definition at line 97 of file tuto4.php.

References $file, FPDF::$title, FPDF::AddPage(), ChapterBody(), and ChapterTitle().

{
    //Add chapter
    $this->AddPage();
    $this->ChapterTitle($num,$title);
    $this->ChapterBody($file);
}

PrintChapter ( num,
title,
file 
)

Definition at line 68 of file tuto3.php.

References $file, FPDF::$title, FPDF::AddPage(), ChapterBody(), and ChapterTitle().

{
    $this->AddPage();
    $this->ChapterTitle($num,$title);
    $this->ChapterBody($file);
}

PutLink ( URL,
txt 
)

Definition at line 92 of file tuto6.php.

References SetStyle(), FPDF::SetTextColor(), and FPDF::Write().

Referenced by WriteHTML().

{
    //Put a hyperlink
    $this->SetTextColor(0,0,255);
    $this->SetStyle('U',true);
    $this->Write(5,$txt,$URL);
    $this->SetStyle('U',false);
    $this->SetTextColor(0);
}

SetCol ( col  ) 

Definition at line 38 of file tuto4.php.

References $col, FPDF::$x, FPDF::SetLeftMargin(), and FPDF::SetX().

Referenced by AcceptPageBreak(), and ChapterBody().

{
    //Set position at a given column
    $this->col=$col;
    $x=10+$col*65;
    $this->SetLeftMargin($x);
    $this->SetX($x);
}

SetStyle ( tag,
enable 
)

Definition at line 79 of file tuto6.php.

References FPDF::SetFont().

Referenced by CloseTag(), OpenTag(), and PutLink().

{
    //Modify style and select corresponding font
    $this->$tag+=($enable ? 1 : -1);
    $style='';
    foreach(array('B','I','U') as $s)
    {
        if($this->$s>0)
            $style.=$s;
    }
    $this->SetFont('',$style);
}

WriteHTML ( html  ) 

Definition at line 22 of file tuto6.php.

References $html, $i, CloseTag(), OpenTag(), PutLink(), and FPDF::Write().

{
    //HTML parser
    $html=str_replace("\n",' ',$html);
    $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
    foreach($a as $i=>$e)
    {
        if($i%2==0)
        {
            //Text
            if($this->HREF)
                $this->PutLink($this->HREF,$e);
            else
                $this->Write(5,$e);
        }
        else
        {
            //Tag
            if($e[0]=='/')
                $this->CloseTag(strtoupper(substr($e,1)));
            else
            {
                //Extract attributes
                $a2=explode(' ',$e);
                $tag=strtoupper(array_shift($a2));
                $attr=array();
                foreach($a2 as $v)
                {
                    if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
                        $attr[strtoupper($a3[1])]=$a3[2];
                }
                $this->OpenTag($tag,$attr);
            }
        }
    }
}


Field Documentation

$B

Definition at line 6 of file tuto6.php.

$col = 0

Definition at line 7 of file tuto4.php.

Referenced by BasicTable(), and SetCol().

$HREF

Definition at line 9 of file tuto6.php.

$I

Definition at line 7 of file tuto6.php.

$U

Definition at line 8 of file tuto6.php.

$y0

Definition at line 9 of file tuto4.php.


The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Enumerations