Files
simak/app/print/pdf_mc_table.php
2025-10-10 09:25:05 +07:00

340 lines
8.8 KiB
PHP

<?php
require('fpdf17/fpdf.php');
class PDF_MC_Table 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;
}
function Row($data)
{
//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;
//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';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Draw the border
$this->Rect($x,$y,$w,$h);
//Print the text
$this->MultiCell($w,5,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function Row0($data)
{
//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;
//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';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Draw the border
//$this->Rect($x,$y,$w,$h);
//Print the text
$this->MultiCell($w,5,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function Row1($data)
{
//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;
//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] : 'C';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Draw the border
$this->Rect($x,$y,$w,$h);
//Print the text
$this->MultiCell($w,5,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function Row2($data)
{
//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;
//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';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Print the text
$this->MultiCell($w,5,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function Row9($data)
{
//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;
$this->CheckPageBreak($h);
$w=$this->widths[0];
$a=isset($this->aligns[0]) ? $this->aligns[0] : 'L';
$x=$this->GetX();
$y=$this->GetY();
$this->Rect($x,$y,$w,$h);
$this->MultiCell($w,5,$data[0],0,$a);
$this->SetXY($x+$w,$y);
$w=$this->widths[1];
$a=isset($this->aligns[1]) ? $this->aligns[1] : 'L';
$x=$this->GetX();
$y=$this->GetY();
$this->Rect($x,$y,$w,$h);
$this->MultiCell($w,5,$data[1],0,$a);
$this->SetXY($x+$w,$y);
$w1=$this->widths[2];
$a1=isset($this->aligns[2]) ? $this->aligns[2] : 'C';
$x1=$this->GetX();
$y1=$this->GetY();
$this->Rect($x1,$y1,$w1,$h);
$this->MultiCell($w1,5,$data[2],0,$a1);
$this->SetXY($x1+$w1,$y1);
$w2=$this->widths[3];
$a2=isset($this->aligns[3]) ? $this->aligns[3] : 'C';
$x2=$this->GetX();
$y2=$this->GetY();
$this->Rect($x2,$y2,$w2,$h);
$this->MultiCell($w2,5,$data[3],0,$a2);
$this->SetXY($x2+$w2,$y2);
$w3=$this->widths[4];
$a3=isset($this->aligns[4]) ? $this->aligns[4] : 'C';
$x3=$this->GetX();
$y3=$this->GetY();
$this->Rect($x3,$y3,$w3,$h);
$this->MultiCell($w3,5,$data[4],0,$a3);
$this->SetXY($x3+$w3,$y3);
$w4=$this->widths[5];
$a4=isset($this->aligns[5]) ? $this->aligns[5] : 'C';
$x4=$this->GetX();
$y4=$this->GetY();
$this->Rect($x4,$y4,$w4,$h);
$this->MultiCell($w4,5,$data[5],0,$a4);
$this->SetXY($x4+$w4,$y4);
$this->Ln($h);
}
function Row10($data)
{
//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;
$this->CheckPageBreak($h);
$w=$this->widths[0];
$a=isset($this->aligns[0]) ? $this->aligns[0] : 'C';
$x=$this->GetX();
$y=$this->GetY();
$this->Rect($x,$y,$w,$h);
$this->MultiCell($w,5,$data[0],0,$a);
$this->SetXY($x+$w,$y);
$w=$this->widths[1];
$a=isset($this->aligns[1]) ? $this->aligns[1] : 'L';
$x=$this->GetX();
$y=$this->GetY();
$this->Rect($x,$y,$w,$h);
$this->MultiCell($w,5,$data[1],0,$a);
$this->SetXY($x+$w,$y);
$w1=$this->widths[2];
$a1=isset($this->aligns[2]) ? $this->aligns[2] : 'L';
$x1=$this->GetX();
$y1=$this->GetY();
$this->Rect($x1,$y1,$w1,$h);
$this->MultiCell($w1,5,$data[2],0,$a1);
$this->SetXY($x1+$w1,$y1);
$w2=$this->widths[3];
$a2=isset($this->aligns[3]) ? $this->aligns[3] : 'C';
$x2=$this->GetX();
$y2=$this->GetY();
$this->Rect($x2,$y2,$w2,$h);
$this->MultiCell($w2,5,$data[3],0,$a2);
$this->SetXY($x2+$w2,$y2);
$w3=$this->widths[4];
$a3=isset($this->aligns[4]) ? $this->aligns[4] : 'C';
$x3=$this->GetX();
$y3=$this->GetY();
$this->Rect($x3,$y3,$w3,$h);
$this->MultiCell($w3,5,$data[4],0,$a3);
$this->SetXY($x3+$w3,$y3);
$w4=$this->widths[5];
$a4=isset($this->aligns[5]) ? $this->aligns[5] : 'R';
$x4=$this->GetX();
$y4=$this->GetY();
$this->Rect($x4,$y4,$w4,$h);
$this->MultiCell($w4,5,$data[5],0,$a4);
$this->SetXY($x4+$w4,$y4);
$w4=$this->widths[6];
$a4=isset($this->aligns[6]) ? $this->aligns[5] : 'R';
$x4=$this->GetX();
$y4=$this->GetY();
$this->Rect($x4,$y4,$w4,$h);
$this->MultiCell($w4,5,$data[6],0,$a4);
$this->SetXY($x4+$w4,$y4);
$w4=$this->widths[7];
$a4=isset($this->aligns[7]) ? $this->aligns[5] : 'C';
$x4=$this->GetX();
$y4=$this->GetY();
$this->Rect($x4,$y4,$w4,$h);
$this->MultiCell($w4,5,$data[7],0,$a4);
$this->SetXY($x4+$w4,$y4);
$w4=$this->widths[8];
$a4=isset($this->aligns[8]) ? $this->aligns[5] : 'C';
$x4=$this->GetX();
$y4=$this->GetY();
$this->Rect($x4,$y4,$w4,$h);
$this->MultiCell($w4,5,$data[8],0,$a4);
$this->SetXY($x4+$w4,$y4);
$w4=$this->widths[9];
$a4=isset($this->aligns[9]) ? $this->aligns[5] : 'C';
$x4=$this->GetX();
$y4=$this->GetY();
$this->Rect($x4,$y4,$w4,$h);
$this->MultiCell($w4,5,$data[9],0,$a4);
$this->SetXY($x4+$w4,$y4);
$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;
}
}
?>