- Add page numbers to lpdf generated reports

- Allow the addTable array to contain an 'option' array, with one supported
  option 'allow_multiline' => if true, it allows cell data to spill into
  mutliple rows, instead of just printing ... if the text doesn't fit.
  
- Ignore the addText2 function, it is for label generation and isn't finished
  yet.
This commit is contained in:
dave 2007-03-18 05:02:14 +00:00
parent a318e2d1fa
commit 7c96874571

View File

@ -111,6 +111,9 @@ class lpdf
pdf_setfont($this->pdf,$this->normalfont,9); pdf_setfont($this->pdf,$this->normalfont,9);
pdf_show_xy($this->pdf,$footertext,$this->loc($this->page_width/2)-$footerwidth/2,$this->loc(0.5)); pdf_show_xy($this->pdf,$footertext,$this->loc($this->page_width/2)-$footerwidth/2,$this->loc(0.5));
pdf_setfont($this->pdf,$this->normalfont,11);
pdf_show_xy($this->pdf,($this->pagenumber),$this->loc($this->page_width - 0.5),$this->loc(0.5));
//footer line //footer line
pdf_moveto($this->pdf,$this->loc($this->page_margin-0.25),$this->loc($this->page_margin-0.05)); pdf_moveto($this->pdf,$this->loc($this->page_margin-0.25),$this->loc($this->page_margin-0.05));
pdf_lineto($this->pdf,$this->loc($this->page_width-$this->page_margin+0.25),$this->loc($this->page_margin-0.05)); pdf_lineto($this->pdf,$this->loc($this->page_width-$this->page_margin+0.25),$this->loc($this->page_margin-0.05));
@ -343,6 +346,27 @@ class lpdf
return $numlines; return $numlines;
} }
function addLabelText2($xp,$yp,$wp,$hp,$text)
{
/* Some assumptions:
- we will scale the font instead of doing line wrapping
- all coords are given in percentages of the label
- a width or height of 0 means "don't care"
- xp or yp can also be 'center', meaning center the text */
if($wp != 0) $desired_width = ($this->label_width * $wp) / 100;
if($hp != 0) $desired_height = ($this->label_height * $hp) / 100;
if($xp == 'center') {
} else {
$xpos = ($xp * $this->label_wdith) / 100;
}
if($yp == 'center') {
} else {
$ypos = ($yp * $this->label_height) / 100;
}
}
function newNametag() function newNametag()
{ {
if($this->current_nametag_index==$this->nametags_per_page) if($this->current_nametag_index==$this->nametags_per_page)
@ -563,6 +587,12 @@ class lpdf
$table_width=array_sum($table['widths']); $table_width=array_sum($table['widths']);
$table_padding=0.03; $table_padding=0.03;
$allow_multiline = false;
if(is_array($table['option'])) {
$allow_multiline = ($table['option']['allow_multiline'] == true) ? true : false;
}
switch($align) switch($align)
{ {
case "center"; $xpos_of_table=($this->page_width-$table_width)/2; break; case "center"; $xpos_of_table=($this->page_width-$table_width)/2; break;
@ -608,8 +638,15 @@ class lpdf
for($c=0;$c<$table_cols;$c++) for($c=0;$c<$table_cols;$c++)
{ {
$width=$table['widths'][$c]; $width=$table['widths'][$c];
$h=0;
$notfit=pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos+$table_padding),$this->loc($this->yloc),$this->loc($width-2*$table_padding),$this->loc($height['tabledata']),$table['dataalign'][$c],null); for($h=1; $h<5;$h++) {
$notfit=pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos+$table_padding),$this->loc($this->yloc),$this->loc($width-2*$table_padding),$this->loc($height['tabledata'])*$h, $table['dataalign'][$c],null);
if($allow_multiline == false) break; // default behaviour, don't try multi lines
if($notfit == 0) {
break;
}
$this->yloc -= $height['tabledata'];
}
//put a little "..." at the end of the field //put a little "..." at the end of the field
if($notfit) if($notfit)
@ -700,6 +737,11 @@ class lpdf
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc)); pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc));
pdf_stroke($this->pdf); pdf_stroke($this->pdf);
// print the total in th etable at the bottom of the table
$t = count($table['data']);
$this->addText("(Total: $t)", 'right');
} }
//page styles: "normal" "nametags" "empty" "labels" //page styles: "normal" "nametags" "empty" "labels"