Stefan: Frage zu einem fpdf-AddOn

Beitrag lesen

FPDF hat eine ausführliche Doku. Wenn Du das Forum dort gefunden hast, schau doch mal bei der entsprechenden Doku rein:
http://www.fpdf.org/en/doc/multicell.htm

Hi Erik,

klar, die kenne ich.

Es geht nicht alleine um die Methode multicell, sondern um ihre Verwendung in Tabellen. Ich drucke eine Artikelliste aus, die einen Artikeltext in einer "Row" hat.

Und das AddOn (php Klasse) "PDF_MC_Table_WA" misst vor dem Einsetzen einer "Row" (also einer multicell-Zeile) den hierfür benötigten Platzbedarf und bricht, wenn ein Overflow existieren würde, die Seite um.

Ich möchte aber haben, dass mein ganz normaler Autopagebreakwert (z.b. 25mm) genutzt wird.

Ich bin inzwischen auch soweit, dass das funktioniert. Leider wird aber dann gleich nach dieser "Row" (also muticell) die Seite umgebrochen und ich habe keinen Schimmer, warum.

Ich poste mal die originale Klasse (ohne meine Änderungen), vielleicht erkennt ja jemand von Euch, warum zum Beispiel nach dem auskommentieren der Zeile

$this->CheckPageBreak($h);

die Klasse zwar für diese "Row" den normalen Autopagewert-Seitenumbruch nutzt, aber anschließend völlig "außer Tritt" gekommen ist und mir sozusagen jedes Wort der nachfolgenden "Rows" zwar in seine entsprechende Spalte (also multicell) setzt, aber für jede multicell eine eigene Seite umbricht.

Stefan

  
<?php  
require('fpdf.php');  
  
class PDF_MC_Table_WA extends FPDF  
{  
var $widths;  
var $aligns;  
  
function SetWidths($w)  
{  
        //Set the array of column widths  
        $this->widths=$w;  
}  
  
function SetAligns($a)  
{  
        //Set the array of column alignments  
        $this->aligns=$a;  
}  
  
//============== by Stephan Gaertner (stegasoft.de) =================  
//-------------- added 14/11/2005 -----------------------------------  
var $borders;  
var $bordercolors;  
var $backgroundcolors;  
var $cellfonts;  
  
function SetBorders($b)  
{  
        //Set the array of borders  
        $this->borders=$b;  
}  
  
function SetBorderColors($b)  
{  
        //Set the array of border colors  
        $this->bordercolors=$b;  
}  
  
function SetBackgroundColors($b)  
{  
        //Set the array of background colors  
        $this->backgroundcolors=$b;  
}  
  
function SetCellFont($cfnt)  
{  
        //Set the array of cell font family  
        $this->cellfonts=$cfnt;  
  
}  
//-------------------------------------------------------------------  
//===================================================================  
  
  
function Row($data,$height=5,$line_height=5)  
{  
        //Calculate the height of the row  
        $nb=0;  
        for($i=0;$i<count($data);$i++)  
                $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));  
        //$h=5*$nb;  
        if($height<($line_height*$nb))  
          $h=$line_height*$nb;  
        else  
          $h=$height;  
        //Issue a page break first if needed  
        $this->CheckPageBreak($h);  
        //Draw the cells of the row  
        for($i=0;$i<count($data);$i++)  
        {  
                $w=$this->widths[$i];  
                $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';  
                $border=strtoupper($this->borders[$i]);  
                $bordercolor=$this->bordercolors[$i];  
                $backgroundcolor=$this->backgroundcolors[$i];  
                $font_attributes=$this->cellfonts[$i];  
                //Save the current position  
                $x=$this->GetX();  
                $y=$this->GetY();  
                //Draw the border  
                if(trim($bordercolor[0])!="") {  
                  if((trim($bordercolor[1])=="") AND (trim($bordercolor[2])==""))  
                    $this->SetDrawColor($bordercolor[0]);  
                  else  
                    $this->SetDrawColor($bordercolor[0],$bordercolor[1],$bordercolor[2]);  
                }  
                if(trim($backgroundcolor[0])!="") {  
                  if((trim($backgroundcolor[1])=="") AND (trim($backgroundcolor[2])==""))  
                    $this->SetFillColor($backgroundcolor[0]);  
                  else  
                    $this->SetFillColor($backgroundcolor[0],$backgroundcolor[1],$backgroundcolor[2]);  
                }  
                if ($border!='0') {  
                  if((strstr($border, 'L')==false) && (strstr($border, 'R')==false) && (strstr($border, 'B')==false) && (strstr($border, 'T')==false)) {  
                    switch ($border) {  
                      case 'D': $this->Rect($x,$y,$w,$h);  
                                break;  
                      case '': $this->Rect($x,$y,$w,$h);  
                               break;  
                      case 'F': $this->Rect($x,$y,$w,$h,'F');  
                                break;  
                      case 'DF': $this->Rect($x,$y,$w,$h,'DF');  
                                 break;  
                      case 'FD': $this->Rect($x,$y,$w,$h,'DF');  
                                 break;  
                    }  
                  }  
                  else {  
                    if (strstr($border, 'F')!==false) {  
                      $this->Rect($x,$y,$w,$h,'F');  
                    }  
                    if (strstr($border, 'L')!==false) {  
                      $this->Line($x, $y, $x, $y+$h);  
                    }  
                    if (strstr($border, 'R')!==false) {  
                      $this->Line($x+$w, $y, $x+$w, $y+$h);  
                    }  
                    if (strstr($border, 'T')!==false) {  
                      $this->Line($x, $y, $x+$w, $y);  
                    }  
                    if (strstr($border, 'B')!==false) {  
                      $this->Line($x, $y+$h, $x+$w, $y+$h);  
                    }  
                  }  
  
                }  
                if(trim($font_attributes[0])!="") {  
                  $this->SetFont($font_attributes[0],$font_attributes[1],$font_attributes[2]);  
                }  
                //Print the text  
                $this->MultiCell($w,$line_height,$data[$i],0,$a,0);  
                //Put the position to the right of the cell  
                $this->SetXY($x+$w,$y);  
        }  
        //Go to the next line  
        $this->Ln($h);  
}  
  
function CheckPageBreak($h)  
{  
        //If the height h would cause an overflow, add a new page immediately  
        if($this->GetY()+$h>$this->PageBreakTrigger)  
                $this->AddPage($this->CurOrientation);  
}  
  
function NbLines($w,$txt)  
{  
        //Computes the number of lines a MultiCell of width w will take  
        $cw=&$this->CurrentFont['cw'];  
        if($w==0)  
                $w=$this->w-$this->rMargin-$this->x;  
        $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;  
        $s=str_replace("\r",'',$txt);  
        $nb=strlen($s);  
        if($nb>0 and $s[$nb-1]=="\n")  
                $nb--;  
        $sep=-1;  
        $i=0;  
        $j=0;  
        $l=0;  
        $nl=1;  
        while($i<$nb)  
        {  
                $c=$s[$i];  
                if($c=="\n")  
                {  
                        $i++;  
                        $sep=-1;  
                        $j=$i;  
                        $l=0;  
                        $nl++;  
                        continue;  
                }  
                if($c==' ')  
                        $sep=$i;  
                $l+=$cw[$c];  
                if($l>$wmax)  
                {  
                        if($sep==-1)  
                        {  
                                if($i==$j)  
                                        $i++;  
                        }  
                        else  
                                $i=$sep+1;  
                        $sep=-1;  
                        $j=$i;  
                        $l=0;  
                        $nl++;  
                }  
                else  
                        $i++;  
        }  
        return $nl;  
}  
  
  
}  
?>