From 7c9687457167c5c1ba262b5cabcc7be59e63e9c6 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 18 Mar 2007 05:02:14 +0000 Subject: [PATCH] - 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. --- lpdf.php | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/lpdf.php b/lpdf.php index e6a067f..28e455e 100644 --- a/lpdf.php +++ b/lpdf.php @@ -111,6 +111,9 @@ class lpdf 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_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 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)); @@ -343,6 +346,27 @@ class lpdf 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() { if($this->current_nametag_index==$this->nametags_per_page) @@ -563,6 +587,12 @@ class lpdf $table_width=array_sum($table['widths']); $table_padding=0.03; + + $allow_multiline = false; + if(is_array($table['option'])) { + $allow_multiline = ($table['option']['allow_multiline'] == true) ? true : false; + } + switch($align) { 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++) { $width=$table['widths'][$c]; - - $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); + $h=0; + 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 if($notfit) @@ -700,6 +737,11 @@ class lpdf pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc)); 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"