Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Cezpdf Class Reference

Inheritance diagram for Cezpdf:

Cpdf Creport

Public Member Functions

 Cezpdf ($paper='a4', $orientation='portrait')
 ezSetCmMargins ($top, $bottom, $left, $right)
 ezColumnsStart ($options=array())
 ezColumnsStop ()
 ezInsertMode ($status=1, $pageNum=1, $pos='before')
 ezNewPage ()
 ezSetMargins ($top, $bottom, $left, $right)
 ezGetCurrentPageNumber ()
 ezStartPageNumbers ($x, $y, $size, $pos='left', $pattern='{PAGENUM}of{TOTALPAGENUM}', $num='')
 ezWhatPageNumber ($pageNum, $i=0)
 ezStopPageNumbers ($stopTotal=0, $next=0, $i=0)
 ezPRVTpageNumberSearch ($lbl, &$tmp)
 ezPRVTaddPageNumbers ()
 ezPRVTcleanUp ()
 ezStream ($options='')
 ezOutput ($options=0)
 ezSetY ($y)
 ezSetDy ($dy, $mod='')
 ezPrvtTableDrawLines ($pos, $gap, $x0, $x1, $y0, $y1, $y2, $col, $inner, $outer, $opt=1)
 ezPrvtTableColumnHeadings ($cols, $pos, $maxWidth, $height, $decender, $gap, $size, &$y, $optionsAll=array())
 ezPrvtGetTextWidth ($size, $text)
 ezTable (&$data, $cols='', $title='', $options='')
 ezProcessText ($text)
 ezText ($text, $size=0, $options=array(), $test=0)
 ezImage ($image, $pad=5, $width=0, $resize= 'full', $just= 'center', $border= '')
 loadTemplate ($templateFile)
 execTemplate ($id, $data=array(), $options=array())
 ilink ($info)
 alink ($info, $internal=0)
 uline ($info)

Data Fields

 $ez = array('fontSize'=>10)
 $y
 $ezPages = array()
 $ezPageCount = 0

Detailed Description

Definition at line 5 of file class.ezpdf.php.


Constructor & Destructor Documentation

Cezpdf::Cezpdf paper = 'a4',
orientation = 'portrait'
 

Definition at line 28 of file class.ezpdf.php.

References $a, $size, Cpdf::Cpdf(), Cpdf::getFirstPageId(), and size.

Referenced by Creport::Creport().

00028                                                     {
00029         // Assuming that people don't want to specify the paper size using the absolute coordinates
00030         // allow a couple of options:
00031         // orientation can be 'portrait' or 'landscape'
00032         // or, to actually set the coordinates, then pass an array in as the first parameter.
00033         // the defaults are as shown.
00034         // 
00035         // -------------------------
00036         // 2002-07-24 - Nicola Asuni (info@tecnick.com):
00037         // Added new page formats (45 standard ISO paper formats and 4 american common formats)
00038         // paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm
00039         // 
00040         // Now you may also pass a 2 values array containing the page width and height in centimeters
00041         // -------------------------
00042 
00043         if (!is_array($paper)){
00044                 switch (strtoupper($paper)){
00045                         case '4A0': {$size = array(0,0,4767.87,6740.79); break;}
00046                         case '2A0': {$size = array(0,0,3370.39,4767.87); break;}
00047                         case 'A0': {$size = array(0,0,2383.94,3370.39); break;}
00048                         case 'A1': {$size = array(0,0,1683.78,2383.94); break;}
00049                         case 'A2': {$size = array(0,0,1190.55,1683.78); break;}
00050                         case 'A3': {$size = array(0,0,841.89,1190.55); break;}
00051                         case 'A4': default: {$size = array(0,0,595.28,841.89); break;}
00052                         case 'A5': {$size = array(0,0,419.53,595.28); break;}
00053                         case 'A6': {$size = array(0,0,297.64,419.53); break;}
00054                         case 'A7': {$size = array(0,0,209.76,297.64); break;}
00055                         case 'A8': {$size = array(0,0,147.40,209.76); break;}
00056                         case 'A9': {$size = array(0,0,104.88,147.40); break;}
00057                         case 'A10': {$size = array(0,0,73.70,104.88); break;}
00058                         case 'B0': {$size = array(0,0,2834.65,4008.19); break;}
00059                         case 'B1': {$size = array(0,0,2004.09,2834.65); break;}
00060                         case 'B2': {$size = array(0,0,1417.32,2004.09); break;}
00061                         case 'B3': {$size = array(0,0,1000.63,1417.32); break;}
00062                         case 'B4': {$size = array(0,0,708.66,1000.63); break;}
00063                         case 'B5': {$size = array(0,0,498.90,708.66); break;}
00064                         case 'B6': {$size = array(0,0,354.33,498.90); break;}
00065                         case 'B7': {$size = array(0,0,249.45,354.33); break;}
00066                         case 'B8': {$size = array(0,0,175.75,249.45); break;}
00067                         case 'B9': {$size = array(0,0,124.72,175.75); break;}
00068                         case 'B10': {$size = array(0,0,87.87,124.72); break;}
00069                         case 'C0': {$size = array(0,0,2599.37,3676.54); break;}
00070                         case 'C1': {$size = array(0,0,1836.85,2599.37); break;}
00071                         case 'C2': {$size = array(0,0,1298.27,1836.85); break;}
00072                         case 'C3': {$size = array(0,0,918.43,1298.27); break;}
00073                         case 'C4': {$size = array(0,0,649.13,918.43); break;}
00074                         case 'C5': {$size = array(0,0,459.21,649.13); break;}
00075                         case 'C6': {$size = array(0,0,323.15,459.21); break;}
00076                         case 'C7': {$size = array(0,0,229.61,323.15); break;}
00077                         case 'C8': {$size = array(0,0,161.57,229.61); break;}
00078                         case 'C9': {$size = array(0,0,113.39,161.57); break;}
00079                         case 'C10': {$size = array(0,0,79.37,113.39); break;}
00080                         case 'RA0': {$size = array(0,0,2437.80,3458.27); break;}
00081                         case 'RA1': {$size = array(0,0,1729.13,2437.80); break;}
00082                         case 'RA2': {$size = array(0,0,1218.90,1729.13); break;}
00083                         case 'RA3': {$size = array(0,0,864.57,1218.90); break;}
00084                         case 'RA4': {$size = array(0,0,609.45,864.57); break;}
00085                         case 'SRA0': {$size = array(0,0,2551.18,3628.35); break;}
00086                         case 'SRA1': {$size = array(0,0,1814.17,2551.18); break;}
00087                         case 'SRA2': {$size = array(0,0,1275.59,1814.17); break;}
00088                         case 'SRA3': {$size = array(0,0,907.09,1275.59); break;}
00089                         case 'SRA4': {$size = array(0,0,637.80,907.09); break;}
00090                         case 'LETTER': {$size = array(0,0,612.00,792.00); break;}
00091                         case 'LEGAL': {$size = array(0,0,612.00,1008.00); break;}
00092                         case 'EXECUTIVE': {$size = array(0,0,521.86,756.00); break;}
00093                         case 'FOLIO': {$size = array(0,0,612.00,936.00); break;}
00094                 }
00095                 switch (strtolower($orientation)){
00096                         case 'landscape':
00097                                 $a=$size[3];
00098                                 $size[3]=$size[2];
00099                                 $size[2]=$a;
00100                                 break;
00101                 }
00102         } else {
00103                 if (count($paper)>2) {
00104                         // then an array was sent it to set the size
00105                         $size = $paper;
00106                 }
00107                 else { //size in centimeters has been passed
00108                         $size[0] = 0;
00109                         $size[1] = 0;
00110                         $size[2] = ( $paper[0] / 2.54 ) * 72;
00111                         $size[3] = ( $paper[1] / 2.54 ) * 72;
00112                 }
00113         }
00114         $this->Cpdf($size);
00115         $this->ez['pageWidth']=$size[2];
00116         $this->ez['pageHeight']=$size[3];
00117         
00118         // also set the margins to some reasonable defaults
00119         $this->ez['topMargin']=30;
00120         $this->ez['bottomMargin']=30;
00121         $this->ez['leftMargin']=30;
00122         $this->ez['rightMargin']=30;
00123         
00124         // set the current writing position to the top of the first page
00125         $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
00126         // and get the ID of the page that was created during the instancing process.
00127         $this->ezPages[1]=$this->getFirstPageId();
00128         $this->ezPageCount=1;
00129 }


Member Function Documentation

Cezpdf::alink info,
internal = 0
 

Definition at line 1473 of file class.ezpdf.php.

References $a, $i, $start, and start.

Referenced by ezTable().

01473                                  {
01474   // a callback function to support the formation of clickable links within the document
01475   $lineFactor=0.05; // the thickness of the line as a proportion of the height. also the drop of the line.
01476   switch($info['status']){
01477     case 'start':
01478     case 'sol':
01479       // the beginning of the link
01480       // this should contain the URl for the link as the 'p' entry, and will also contain the value of 'nCallback'
01481       if (!isset($this->ez['links'])){
01482         $this->ez['links']=array();
01483       }
01484       $i = $info['nCallback'];
01485       $this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height'],'url'=>$info['p']);
01486       if ($internal==0){
01487         $this->saveState();
01488         $this->setColor(0,0,1);
01489         $this->setStrokeColor(0,0,1);
01490         $thick = $info['height']*$lineFactor;
01491         $this->setLineStyle($thick);
01492       }
01493       break;
01494     case 'end':
01495     case 'eol':
01496       // the end of the link
01497       // assume that it is the most recent opening which has closed
01498       $i = $info['nCallback'];
01499       $start = $this->ez['links'][$i];
01500       // add underlining
01501       if ($internal){
01502         $this->addInternalLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);
01503       } else {
01504         $a = deg2rad((float)$start['angle']-90.0);
01505         $drop = $start['height']*$lineFactor*1.5;
01506         $dropx = cos($a)*$drop;
01507         $dropy = -sin($a)*$drop;
01508         $this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);
01509         $this->addLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);
01510         $this->restoreState();
01511       }
01512       break;
01513   }
01514 }

Cezpdf::execTemplate id,
data = array(),
options = array()
 

Definition at line 1460 of file class.ezpdf.php.

01460                                                          {
01461   // execute the given template on the current document.
01462   if (!isset($this->ez['templates'][$id])){
01463     return;
01464   }
01465   eval($this->ez['templates'][$id]['code']);
01466 }

Cezpdf::ezColumnsStart options = array()  ) 
 

Definition at line 144 of file class.ezpdf.php.

References Cpdf::$options, and width.

00144                                          {
00145   // start from the current y-position, make the set number of columne
00146   if (isset($this->ez['columns']) && $this->ez['columns']==1){
00147     // if we are already in a column mode then just return.
00148     return;
00149   }
00150   $def=array('gap'=>10,'num'=>2);
00151   foreach($def as $k=>$v){
00152     if (!isset($options[$k])){
00153       $options[$k]=$v;
00154     }
00155   }
00156   // setup the columns
00157   $this->ez['columns']=array('on'=>1,'colNum'=>1);
00158 
00159   // store the current margins
00160   $this->ez['columns']['margins']=array(
00161      $this->ez['leftMargin']
00162     ,$this->ez['rightMargin']
00163     ,$this->ez['topMargin']
00164     ,$this->ez['bottomMargin']
00165   );
00166   // and store the settings for the columns
00167   $this->ez['columns']['options']=$options;
00168   // then reset the margins to suit the new columns
00169   // safe enough to assume the first column here, but start from the current y-position
00170   $this->ez['topMargin']=$this->ez['pageHeight']-$this->y;
00171   $width=($this->ez['pageWidth']-$this->ez['leftMargin']-$this->ez['rightMargin']-($options['num']-1)*$options['gap'])/$options['num'];
00172   $this->ez['columns']['width']=$width;
00173   $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;
00174   
00175 }

Cezpdf::ezColumnsStop  ) 
 

Definition at line 177 of file class.ezpdf.php.

00177                         {
00178   if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
00179     $this->ez['columns']['on']=0;
00180     $this->ez['leftMargin']=$this->ez['columns']['margins'][0];
00181     $this->ez['rightMargin']=$this->ez['columns']['margins'][1];
00182     $this->ez['topMargin']=$this->ez['columns']['margins'][2];
00183     $this->ez['bottomMargin']=$this->ez['columns']['margins'][3];
00184   }
00185 }

Cezpdf::ezGetCurrentPageNumber  ) 
 

Definition at line 266 of file class.ezpdf.php.

00266                                  {
00267   // return the strict numbering (1,2,3,4..) number of the current page
00268   return $this->ezPageCount;
00269 }

Cezpdf::ezImage image,
pad = 5,
width = 0,
resize = 'full',
just = 'center',
border = ''
 

Definition at line 1301 of file class.ezpdf.php.

References width.

01301                                                                                            {
01302         //beta ezimage function
01303         if (stristr($image,'://'))//copy to temp file
01304         {
01305                 $fp = @fopen($image,"rb");
01306                 while(!feof($fp))
01307                 {
01308                         $cont.= fread($fp,1024);
01309                 }
01310                 fclose($fp);
01311                 $image = tempnam ("/tmp", "php-pdf");
01312                 $fp2 = @fopen($image,"w");
01313                 fwrite($fp2,$cont);
01314                 fclose($fp2);
01315                 $temp = true;
01316         }
01317 
01318         if (!(file_exists($image))) return false; //return immediately if image file does not exist
01319         $imageInfo = getimagesize($image);
01320         switch ($imageInfo[2]){
01321                 case 2:
01322                         $type = "jpeg";
01323                         break;
01324                 case 3:
01325                         $type = "png";
01326                         break;
01327                 default:
01328                         return false; //return if file is not jpg or png
01329         }
01330         if ($width == 0) $width = $imageInfo[0]; //set width
01331         $ratio = $imageInfo[0]/$imageInfo[1];
01332 
01333         //get maximum width of image
01334         if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
01335         {
01336                 $bigwidth = $this->ez['columns']['width'] - ($pad * 2);
01337         }
01338         else
01339         {
01340                 $bigwidth = $this->ez['pageWidth'] - ($pad * 2);
01341         }
01342         //fix width if larger than maximum or if $resize=full
01343         if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)
01344         {
01345                 $width = $bigwidth;
01346 
01347         }
01348 
01349         $height = ($width/$ratio); //set height
01350 
01351         //fix size if runs off page
01352         if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))
01353         {
01354                 if ($resize != 'full')
01355                 {
01356                         $this->ezNewPage();
01357                 }
01358                 else
01359                 {
01360                         $height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2)); //shrink height
01361                         $width = ($height*$ratio); //fix width
01362                 }
01363         }
01364 
01365         //fix x-offset if image smaller than bigwidth
01366         if ($width < $bigwidth)
01367         {
01368                 //center if justification=center
01369                 if ($just == 'center')
01370                 {
01371                         $offset = ($bigwidth - $width) / 2;
01372                 }
01373                 //move to right if justification=right
01374                 if ($just == 'right')
01375                 {
01376                         $offset = ($bigwidth - $width);
01377                 }
01378                 //leave at left if justification=left
01379                 if ($just == 'left')
01380                 {
01381                         $offset = 0;
01382                 }
01383         }
01384 
01385 
01386         //call appropriate function
01387         if ($type == "jpeg"){
01388                 $this->addJpegFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
01389         }
01390 
01391         if ($type == "png"){
01392                 $this->addPngFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
01393         }
01394         //draw border
01395         if ($border != '')
01396         {
01397         if (!(isset($border['color'])))
01398         {
01399                 $border['color']['red'] = .5;
01400                 $border['color']['blue'] = .5;
01401                 $border['color']['green'] = .5;
01402         }
01403         if (!(isset($border['width']))) $border['width'] = 1;
01404         if (!(isset($border['cap']))) $border['cap'] = 'round';
01405         if (!(isset($border['join']))) $border['join'] = 'round';
01406         
01407 
01408         $this->setStrokeColor($border['color']['red'],$border['color']['green'],$border['color']['blue']);
01409         $this->setLineStyle($border['width'],$border['cap'],$border['join']);
01410         $this->rectangle($this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width,$height);
01411 
01412         }
01413         // move y below image
01414         $this->y = $this->y - $pad - $height;
01415         //remove tempfile for remote images
01416         if ($temp == true) unlink($image);
01417 
01418 }

Cezpdf::ezInsertMode status = 1,
pageNum = 1,
pos = 'before'
 

Definition at line 187 of file class.ezpdf.php.

00187                                                          {
00188   // puts the document into insert mode. new pages are inserted until this is re-called with status=0
00189   // by default pages wil be inserted at the start of the document
00190   switch($status){
00191     case '1':
00192       if (isset($this->ezPages[$pageNum])){
00193         $this->ez['insertMode']=1;
00194         $this->ez['insertOptions']=array('id'=>$this->ezPages[$pageNum],'pos'=>$pos);
00195       }
00196       break;
00197     case '0':
00198       $this->ez['insertMode']=0;
00199       break;
00200   }
00201 }

Cezpdf::ezNewPage  ) 
 

Definition at line 204 of file class.ezpdf.php.

References Cpdf::newPage(), and width.

Referenced by ezPrvtTableColumnHeadings(), ezSetDy(), ezSetMargins(), ezSetY(), ezTable(), and ezText().

00204                     {
00205   $pageRequired=1;
00206   if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
00207     // check if this is just going to a new column
00208     // increment the column number
00209 //echo 'HERE<br>';
00210     $this->ez['columns']['colNum']++;
00211 //echo $this->ez['columns']['colNum'].'<br>';
00212     if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num']){
00213       // then just reset to the top of the next column
00214       $pageRequired=0;
00215     } else {
00216       $this->ez['columns']['colNum']=1;
00217       $this->ez['topMargin']=$this->ez['columns']['margins'][2];
00218     }
00219 
00220     $width = $this->ez['columns']['width'];
00221     $this->ez['leftMargin']=$this->ez['columns']['margins'][0]+($this->ez['columns']['colNum']-1)*($this->ez['columns']['options']['gap']+$width);
00222     $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;
00223   }
00224 //echo 'left='.$this->ez['leftMargin'].'   right='.$this->ez['rightMargin'].'<br>';
00225 
00226   if ($pageRequired){
00227     // make a new page, setting the writing point back to the top
00228     $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
00229     // make the new page with a call to the basic class.
00230     $this->ezPageCount++;
00231     if (isset($this->ez['insertMode']) && $this->ez['insertMode']==1){
00232       $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1,$this->ez['insertOptions']['id'],$this->ez['insertOptions']['pos']);
00233       // then manipulate the insert options so that inserted pages follow each other
00234       $this->ez['insertOptions']['id']=$id;
00235       $this->ez['insertOptions']['pos']='after';
00236     } else {
00237       $this->ezPages[$this->ezPageCount] = $this->newPage();
00238     }
00239   } else {
00240     $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
00241   }
00242 }

Cezpdf::ezOutput options = 0  ) 
 

Definition at line 461 of file class.ezpdf.php.

References ezPRVTcleanUp(), and Cpdf::output().

00461                              {
00462   $this->ezPRVTcleanUp();
00463   return $this->output($options);
00464 }

Cezpdf::ezProcessText text  ) 
 

Definition at line 1195 of file class.ezpdf.php.

References $search.

Referenced by ezTable(), and ezText().

01195                              {
01196   // this function will intially be used to implement underlining support, but could be used for a range of other
01197   // purposes
01198   $search = array('<u>','<U>','</u>','</U>');
01199   $replace = array('<c:uline>','<c:uline>','</c:uline>','</c:uline>');
01200   return str_replace($search,$replace,$text);
01201 }

Cezpdf::ezPRVTaddPageNumbers  ) 
 

Definition at line 377 of file class.ezpdf.php.

References $l, $num, $tmp, $w, Cpdf::addText(), Cpdf::closeObject(), ezPRVTpageNumberSearch(), Cpdf::getTextWidth(), Cpdf::reopenObject(), and size.

Referenced by ezPRVTcleanUp().

00377                                {
00378   // this will go through the pageNumbering array and add the page numbers are required
00379   if (isset($this->ez['pageNumbering'])){
00380     $totalPages1 = $this->ezPageCount;
00381     $tmp1=$this->ez['pageNumbering'];
00382     $status=0;
00383     foreach($tmp1 as $i=>$tmp){
00384       // do each of the page numbering systems
00385       // firstly, find the total pages for this one
00386       $k = $this->ezPRVTpageNumberSearch('stopt',$tmp);
00387       if ($k && $k>0){
00388         $totalPages = $k-1;
00389       } else {
00390         $l = $this->ezPRVTpageNumberSearch('stoptn',$tmp);
00391         if ($l && $l>0){
00392           $totalPages = $l;
00393         } else {
00394           $totalPages = $totalPages1;
00395         }
00396       }
00397       foreach ($this->ezPages as $pageNum=>$id){
00398         if (isset($tmp[$pageNum])){
00399           if (is_array($tmp[$pageNum])){
00400             // then this must be starting page numbers
00401             $status=1;
00402             $info = $tmp[$pageNum];
00403             $info['dnum']=$info['num']-$pageNum;
00404             // also check for the special case of the numbering stopping and starting on the same page
00405             if (isset($info['stopn']) || isset($info['stoptn']) ){
00406               $status=2;
00407             }
00408           } else if ($tmp[$pageNum]=='stop' || $tmp[$pageNum]=='stopt'){
00409             // then we are stopping page numbers
00410             $status=0;
00411           } else if ($status==1 && ($tmp[$pageNum]=='stoptn' || $tmp[$pageNum]=='stopn')){
00412             // then we are stopping page numbers
00413             $status=2;
00414           }
00415         }
00416         if ($status){
00417           // then add the page numbering to this page
00418           if (strlen($info['num'])){
00419             $num=$pageNum+$info['dnum'];
00420           } else {
00421             $num=$pageNum;
00422           }
00423           $total = $totalPages+$num-$pageNum;
00424           $pat = str_replace('{PAGENUM}',$num,$info['pattern']);
00425           $pat = str_replace('{TOTALPAGENUM}',$total,$pat);
00426           $this->reopenObject($id);
00427           switch($info['pos']){
00428             case 'right':
00429               $this->addText($info['x'],$info['y'],$info['size'],$pat);
00430               break;
00431             default:
00432               $w=$this->getTextWidth($info['size'],$pat);
00433               $this->addText($info['x']-$w,$info['y'],$info['size'],$pat);
00434               break;
00435           }
00436           $this->closeObject();
00437         }
00438         if ($status==2){
00439           $status=0;
00440         }
00441       }
00442     }
00443   }
00444 }

Cezpdf::ezPRVTcleanUp  ) 
 

Definition at line 448 of file class.ezpdf.php.

References ezPRVTaddPageNumbers().

Referenced by ezOutput(), and ezStream().

00448                         {
00449   $this->ezPRVTaddPageNumbers();
00450 }

Cezpdf::ezPrvtGetTextWidth size,
text
 

Definition at line 591 of file class.ezpdf.php.

References $w, Cpdf::getTextWidth(), Cpdf::line(), and size.

Referenced by ezTable().

00591                                         {
00592   // will calculate the maximum width, taking into account that the text may be broken
00593   // by line breaks.
00594   $mx=0;
00595   $lines = explode("\n",$text);
00596   foreach ($lines as $line){
00597     $w = $this->getTextWidth($size,$line);
00598     if ($w>$mx){
00599       $mx=$w;
00600     }
00601   }
00602   return $mx;
00603 }

Cezpdf::ezPRVTpageNumberSearch lbl,
&$  tmp
 

Definition at line 360 of file class.ezpdf.php.

References $i.

Referenced by ezPRVTaddPageNumbers().

00360                                            {
00361   foreach($tmp as $i=>$v){
00362     if (is_array($v)){
00363       if (isset($v[$lbl])){
00364         return $i;
00365       }
00366     } else {
00367       if ($v==$lbl){
00368         return $i;
00369       }
00370     }
00371   }
00372   return 0;
00373 }

Cezpdf::ezPrvtTableColumnHeadings cols,
pos,
maxWidth,
height,
decender,
gap,
size,
&$  y,
optionsAll = array()
 

Definition at line 526 of file class.ezpdf.php.

References $ok, Cpdf::$options, $y, ezNewPage(), ezSetY(), ezText(), size, start, and Cpdf::transaction().

Referenced by ezTable().

00526                                                                                                              {
00527   // uses ezText to add the text, and returns the height taken by the largest heading
00528   // this page will move the headings to a new page if they will not fit completely on this one
00529   // transaction support will be used to implement this
00530 
00531   if (isset($optionsAll['cols'])){
00532     $options = $optionsAll['cols'];
00533   } else {
00534     $options = array();
00535   }
00536   
00537   $mx=0;
00538   $startPage = $this->ezPageCount;
00539   $secondGo=0;
00540 
00541   // $y is the position at which the top of the table should start, so the base
00542   // of the first text, is $y-$height-$gap-$decender, but ezText starts by dropping $height
00543   
00544   // the return from this function is the total cell height, including gaps, and $y is adjusted
00545   // to be the postion of the bottom line
00546   
00547   // begin the transaction
00548   $this->transaction('start');
00549   $ok=0;
00550 //  $y-=$gap-$decender;
00551   $y-=$gap;
00552   while ($ok==0){
00553     foreach($cols as $colName=>$colHeading){
00554       $this->ezSetY($y);
00555       if (isset($options[$colName]) && isset($options[$colName]['justification'])){
00556         $justification = $options[$colName]['justification'];
00557       } else {
00558         $justification = 'left';
00559       }
00560       $this->ezText($colHeading,$size,array('aleft'=> $pos[$colName],'aright'=>($maxWidth[$colName]+$pos[$colName]),'justification'=>$justification));
00561       $dy = $y-$this->y;
00562       if ($dy>$mx){
00563         $mx=$dy;
00564       }
00565     }
00566     $y = $y - $mx - $gap + $decender;
00567 //    $y -= $mx-$gap+$decender;
00568     
00569     // now, if this has moved to a new page, then abort the transaction, move to a new page, and put it there
00570     // do not check on the second time around, to avoid an infinite loop
00571     if ($this->ezPageCount != $startPage && $secondGo==0){
00572       $this->transaction('rewind');
00573       $this->ezNewPage();
00574       $y = $this->y - $gap-$decender;
00575       $ok=0;
00576       $secondGo=1;
00577 //      $y = $store_y;
00578       $mx=0;
00579 
00580     } else {
00581       $this->transaction('commit');
00582       $ok=1;
00583     }
00584   }
00585 
00586   return $mx+$gap*2-$decender;
00587 }

Cezpdf::ezPrvtTableDrawLines pos,
gap,
x0,
x1,
y0,
y1,
y2,
col,
inner,
outer,
opt = 1
 

Definition at line 497 of file class.ezpdf.php.

References $n, $x, Cpdf::line(), Cpdf::setLineStyle(), and Cpdf::setStrokeColor().

Referenced by ezTable().

00497                                                                                       {
00498   $x0=1000;
00499   $x1=0;
00500   $this->setStrokeColor($col[0],$col[1],$col[2]);
00501   $cnt=0;
00502   $n = count($pos);
00503   foreach($pos as $x){
00504     $cnt++;
00505     if ($cnt==1 || $cnt==$n){
00506       $this->setLineStyle($outer);
00507     } else {
00508       $this->setLineStyle($inner);
00509     }
00510     $this->line($x-$gap/2,$y0,$x-$gap/2,$y2);
00511     if ($x>$x1){ $x1=$x; };
00512     if ($x<$x0){ $x0=$x; };
00513   }
00514   $this->setLineStyle($outer);
00515   $this->line($x0-$gap/2-$outer/2,$y0,$x1-$gap/2+$outer/2,$y0);
00516   // only do the second line if it is different to the first, AND each row does not have
00517   // a line on it.
00518   if ($y0!=$y1 && $opt<2){
00519     $this->line($x0-$gap/2,$y1,$x1-$gap/2,$y1);
00520   }
00521   $this->line($x0-$gap/2-$outer/2,$y2,$x1-$gap/2+$outer/2,$y2);
00522 }

Cezpdf::ezSetCmMargins top,
bottom,
left,
right
 

Definition at line 134 of file class.ezpdf.php.

References $right, and ezSetMargins().

00134                                                   {
00135         $top = ( $top / 2.54 ) * 72;
00136         $bottom = ( $bottom / 2.54 ) * 72;
00137         $left = ( $left / 2.54 ) * 72;
00138         $right = ( $right / 2.54 ) * 72;
00139         $this->ezSetMargins($top,$bottom,$left,$right);
00140 }

Cezpdf::ezSetDy dy,
mod = ''
 

Definition at line 479 of file class.ezpdf.php.

References ezNewPage().

00479                              {
00480   // used to change the vertical position of the writing point.
00481   // changes up by a positive increment, so enter a negative number to go
00482   // down the page
00483   // if $mod is set to 'makeSpace' and a new page is forced, then the pointed will be moved 
00484   // down on the new page, this will allow space to be reserved for graphics etc.
00485   $this->y += $dy;
00486   if ( $this->y < $this->ez['bottomMargin']){
00487     // then make a new page
00488     $this->ezNewPage();
00489     if ($mod=='makeSpace'){
00490       $this->y += $dy;
00491     }
00492   }
00493 }

Cezpdf::ezSetMargins top,
bottom,
left,
right
 

Definition at line 246 of file class.ezpdf.php.

References $right, and ezNewPage().

Referenced by ezSetCmMargins().

00246                                                 {
00247   // sets the margins to new values
00248   $this->ez['topMargin']=$top;
00249   $this->ez['bottomMargin']=$bottom;
00250   $this->ez['leftMargin']=$left;
00251   $this->ez['rightMargin']=$right;
00252   // check to see if this means that the current writing position is outside the 
00253   // writable area
00254   if ($this->y > $this->ez['pageHeight']-$top){
00255     // then move y down
00256     $this->y = $this->ez['pageHeight']-$top;
00257   }
00258   if ( $this->y < $bottom){
00259     // then make a new page
00260     $this->ezNewPage();
00261   }
00262 }  

Cezpdf::ezSetY y  ) 
 

Definition at line 468 of file class.ezpdf.php.

References $y, and ezNewPage().

Referenced by ezPrvtTableColumnHeadings(), and ezTable().

00468                    {
00469   // used to change the vertical position of the writing point.
00470   $this->y = $y;
00471   if ( $this->y < $this->ez['bottomMargin']){
00472     // then make a new page
00473     $this->ezNewPage();
00474   }
00475 }

Cezpdf::ezStartPageNumbers x,
y,
size,
pos = 'left'
 

Definition at line 273 of file class.ezpdf.php.

References $i, and size.

Referenced by ezWhatPageNumber().

00273                                                               {PAGENUM} of {TOTALPAGENUM}',$num=''){
00274   // put page numbers on the pages from here.
00275   // place then on the 'pos' side of the coordinates (x,y).
00276   // pos can be 'left' or 'right'
00277   // use the given 'pattern' for display, where (PAGENUM} and {TOTALPAGENUM} are replaced
00278   // as required.
00279   // if $num is set, then make the first page this number, the number of total pages will
00280   // be adjusted to account for this.
00281   // Adjust this function so that each time you 'start' page numbers then you effectively start a different batch
00282   // return the number of the batch, so that they can be stopped in a different order if required.
00283   if (!$pos || !strlen($pos)){
00284     $pos='left';
00285   }
00286   if (!$pattern || !strlen($pattern)){
00287     $pattern='{PAGENUM} of {TOTALPAGENUM}';
00288   }
00289   if (!isset($this->ez['pageNumbering'])){
00290     $this->ez['pageNumbering']=array();
00291   }
00292   $i = count($this->ez['pageNumbering']);
00293   $this->ez['pageNumbering'][$i][$this->ezPageCount]=array('x'=>$x,'y'=>$y,'pos'=>$pos,'pattern'=>$pattern,'num'=>$num,'size'=>$size);
00294   return $i;
00295 }

Cezpdf::ezStopPageNumbers stopTotal = 0,
next = 0,
i = 0
 

Definition at line 331 of file class.ezpdf.php.

References $i.

00331                                                      {
00332   // if stopTotal=1 then the totalling of pages for this number will stop too
00333   // if $next=1, then do this page, but not the next, else do not do this page either
00334   // if $i is set, then stop that particular pagenumbering sequence.
00335   if (!isset($this->ez['pageNumbering'])){
00336     $this->ez['pageNumbering']=array();
00337   }
00338   if ($next && isset($this->ez['pageNumbering'][$i][$this->ezPageCount]) && is_array($this->ez['pageNumbering'][$i][$this->ezPageCount])){
00339     // then this has only just been started, this will over-write the start, and nothing will appear
00340     // add a special command to the start block, telling it to stop as well
00341     if ($stopTotal){
00342       $this->ez['pageNumbering'][$i][$this->ezPageCount]['stoptn']=1;
00343     } else {
00344       $this->ez['pageNumbering'][$i][$this->ezPageCount]['stopn']=1;
00345     }
00346   } else {
00347     if ($stopTotal){
00348       $this->ez['pageNumbering'][$i][$this->ezPageCount]='stopt';
00349     } else {
00350       $this->ez['pageNumbering'][$i][$this->ezPageCount]='stop';
00351     }
00352     if ($next){
00353       $this->ez['pageNumbering'][$i][$this->ezPageCount].='n';
00354     }
00355   }
00356 }

Cezpdf::ezStream options = ''  ) 
 

Definition at line 454 of file class.ezpdf.php.

References ezPRVTcleanUp(), and Cpdf::stream().

00454                               {
00455   $this->ezPRVTcleanUp();
00456   $this->stream($options);
00457 }

Cezpdf::ezTable &$  data,
cols = '',
title = '',
options = ''
 

Definition at line 607 of file class.ezpdf.php.

References $height, $line, $ok, Cpdf::$options, $p, $row, $start, $t, $w, $x, $y, Cpdf::addObject(), Cpdf::addText(), Cpdf::addTextWrap(), alink(), Cpdf::closeObject(), ezNewPage(), ezProcessText(), ezPrvtGetTextWidth(), ezPrvtTableColumnHeadings(), ezPrvtTableDrawLines(), ezSetY(), Cpdf::filledRectangle(), Cpdf::getFontDecender(), Cpdf::getFontHeight(), Cpdf::getTextWidth(), Cpdf::line(), Cpdf::newPage(), Cpdf::openObject(), Cpdf::reopenObject(), Cpdf::restoreState(), Cpdf::saveState(), Cpdf::setColor(), Cpdf::setLineStyle(), Cpdf::setStrokeColor(), start, Cpdf::transaction(), value, and width.

00607                                                        {
00608   // add a table of information to the pdf document
00609   // $data is a two dimensional array
00610   // $cols (optional) is an associative array, the keys are the names of the columns from $data
00611   // to be presented (and in that order), the values are the titles to be given to the columns
00612   // $title (optional) is the title to be put on the top of the table
00613   //
00614   // $options is an associative array which can contain:
00615   // 'showLines'=> 0,1,2, default is 1 (show outside and top lines only), 2=> lines on each row
00616   // 'showHeadings' => 0 or 1
00617   // 'shaded'=> 0,1,2,3 default is 1 (1->alternate lines are shaded, 0->no shading, 2-> both shaded, second uses shadeCol2)
00618   // 'shadeCol' => (r,g,b) array, defining the colour of the shading, default is (0.8,0.8,0.8)
00619   // 'shadeCol2' => (r,g,b) array, defining the colour of the shading of the other blocks, default is (0.7,0.7,0.7)
00620   // 'fontSize' => 10
00621   // 'textCol' => (r,g,b) array, text colour
00622   // 'titleFontSize' => 12
00623   // 'rowGap' => 2 , the space added at the top and bottom of each row, between the text and the lines
00624   // 'colGap' => 5 , the space on the left and right sides of each cell
00625   // 'lineCol' => (r,g,b) array, defining the colour of the lines, default, black.
00626   // 'xPos' => 'left','right','center','centre',or coordinate, reference coordinate in the x-direction
00627   // 'xOrientation' => 'left','right','center','centre', position of the table w.r.t 'xPos' 
00628   // 'width'=> <number> which will specify the width of the table, if it turns out to not be this
00629   //    wide, then it will stretch the table to fit, if it is wider then each cell will be made
00630   //    proportionalty smaller, and the content may have to wrap.
00631   // 'maxWidth'=> <number> similar to 'width', but will only make table smaller than it wants to be
00632   // 'options' => array(<colname>=>array('justification'=>'left','width'=>100,'link'=>linkDataName),<colname>=>....)
00633   //             allow the setting of other paramaters for the individual columns
00634   // 'minRowSpace'=> the minimum space between the bottom of each row and the bottom margin, in which a new row will be started
00635   //                  if it is less, then a new page would be started, default=-100
00636   // 'innerLineThickness'=>1
00637   // 'outerLineThickness'=>1
00638   // 'splitRows'=>0, 0 or 1, whether or not to allow the rows to be split across page boundaries
00639   // 'protectRows'=>number, the number of rows to hold with the heading on page, ie, if there less than this number of
00640   //                rows on the page, then move the whole lot onto the next page, default=1
00641   //
00642   // note that the user will have had to make a font selection already or this will not 
00643   // produce a valid pdf file.
00644   
00645   if (!is_array($data)){
00646     return;
00647   }
00648   
00649   if (!is_array($cols)){
00650     // take the columns from the first row of the data set
00651     reset($data);
00652     list($k,$v)=each($data);
00653     if (!is_array($v)){
00654       return;
00655     }
00656     $cols=array();
00657     foreach($v as $k1=>$v1){
00658       $cols[$k1]=$k1;
00659     }
00660   }
00661   
00662   if (!is_array($options)){
00663     $options=array();
00664   }
00665 
00666   $defaults = array(
00667     'shaded'=>1,'showLines'=>1,'shadeCol'=>array(0.8,0.8,0.8),'shadeCol2'=>array(0.7,0.7,0.7),'fontSize'=>10,'titleFontSize'=>12
00668     ,'titleGap'=>5,'lineCol'=>array(0,0,0),'gap'=>5,'xPos'=>'centre','xOrientation'=>'centre'
00669     ,'showHeadings'=>1,'textCol'=>array(0,0,0),'width'=>0,'maxWidth'=>0,'cols'=>array(),'minRowSpace'=>-100,'rowGap'=>2,'colGap'=>5
00670     ,'innerLineThickness'=>1,'outerLineThickness'=>1,'splitRows'=>0,'protectRows'=>1
00671     );
00672 
00673   foreach($defaults as $key=>$value){
00674     if (is_array($value)){
00675       if (!isset($options[$key]) || !is_array($options[$key])){
00676         $options[$key]=$value;
00677       }
00678     } else {
00679       if (!isset($options[$key])){
00680         $options[$key]=$value;
00681       }
00682     }
00683   }
00684   $options['gap']=2*$options['colGap'];
00685   
00686   $middle = ($this->ez['pageWidth']-$this->ez['rightMargin'])/2+($this->ez['leftMargin'])/2;
00687   // figure out the maximum widths of the text within each column
00688   $maxWidth=array();
00689   foreach($cols as $colName=>$colHeading){
00690     $maxWidth[$colName]=0;
00691   }
00692   // find the maximum cell widths based on the data
00693   foreach($data as $row){
00694     foreach($cols as $colName=>$colHeading){
00695       $w = $this->ezPrvtGetTextWidth($options['fontSize'],(string)$row[$colName])*1.01;
00696       if ($w > $maxWidth[$colName]){
00697         $maxWidth[$colName]=$w;
00698       }
00699     }
00700   }
00701   // and the maximum widths to fit in the headings
00702   foreach($cols as $colName=>$colTitle){
00703     $w = $this->ezPrvtGetTextWidth($options['fontSize'],(string)$colTitle)*1.01;
00704     if ($w > $maxWidth[$colName]){
00705       $maxWidth[$colName]=$w;
00706     }
00707   }
00708   
00709   // calculate the start positions of each of the columns
00710   $pos=array();
00711   $x=0;
00712   $t=$x;
00713   $adjustmentWidth=0;
00714   $setWidth=0;
00715   foreach($maxWidth as $colName => $w){
00716     $pos[$colName]=$t;
00717     // if the column width has been specified then set that here, also total the
00718     // width avaliable for adjustment
00719     if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['width']) && $options['cols'][$colName]['width']>0){
00720       $t=$t+$options['cols'][$colName]['width'];
00721       $maxWidth[$colName] = $options['cols'][$colName]['width']-$options['gap'];
00722       $setWidth += $options['cols'][$colName]['width'];
00723     } else {
00724       $t=$t+$w+$options['gap'];
00725       $adjustmentWidth += $w;
00726       $setWidth += $options['gap'];
00727     }
00728   }
00729   $pos['_end_']=$t;
00730 
00731   // if maxWidth is specified, and the table is too wide, and the width has not been set,
00732   // then set the width.
00733   if ($options['width']==0 && $options['maxWidth'] && ($t-$x)>$options['maxWidth']){
00734     // then need to make this one smaller
00735     $options['width']=$options['maxWidth'];
00736   }
00737 
00738   if ($options['width'] && $adjustmentWidth>0 && $setWidth<$options['width']){
00739     // first find the current widths of the columns involved in this mystery
00740     $cols0 = array();
00741     $cols1 = array();
00742     $xq=0;
00743     $presentWidth=0;
00744     $last='';
00745     foreach($pos as $colName=>$p){
00746       if (!isset($options['cols'][$last]) || !isset($options['cols'][$last]['width']) || $options['cols'][$last]['width']<=0){
00747         if (strlen($last)){
00748           $cols0[$last]=$p-$xq -$options['gap'];
00749           $presentWidth += ($p-$xq - $options['gap']);
00750         }
00751       } else {
00752         $cols1[$last]=$p-$xq;
00753       }
00754       $last=$colName;
00755       $xq=$p;
00756     }
00757     // $cols0 contains the widths of all the columns which are not set
00758     $neededWidth = $options['width']-$setWidth;
00759     // if needed width is negative then add it equally to each column, else get more tricky
00760     if ($presentWidth<$neededWidth){
00761       foreach($cols0 as $colName=>$w){
00762         $cols0[$colName]+= ($neededWidth-$presentWidth)/count($cols0);
00763       }
00764     } else {
00765     
00766       $cnt=0;
00767       while ($presentWidth>$neededWidth && $cnt<100){
00768         $cnt++; // insurance policy
00769         // find the widest columns, and the next to widest width
00770         $aWidest = array();
00771         $nWidest=0;
00772         $widest=0;
00773         foreach($cols0 as $colName=>$w){
00774           if ($w>$widest){
00775             $aWidest=array($colName);
00776             $nWidest = $widest;
00777             $widest=$w;
00778           } else if ($w==$widest){
00779             $aWidest[]=$colName;
00780           }
00781         }
00782         // then figure out what the width of the widest columns would have to be to take up all the slack
00783         $newWidestWidth = $widest - ($presentWidth-$neededWidth)/count($aWidest);
00784         if ($newWidestWidth > $nWidest){
00785           // then there is space to set them to this
00786           foreach($aWidest as $colName){
00787             $cols0[$colName] = $newWidestWidth;
00788           }
00789           $presentWidth=$neededWidth;
00790         } else {
00791           // there is not space, reduce the size of the widest ones down to the next size down, and we
00792           // will go round again
00793           foreach($aWidest as $colName){
00794             $cols0[$colName] = $nWidest;
00795           }
00796           $presentWidth=$presentWidth-($widest-$nWidest)*count($aWidest);
00797         }
00798       }
00799     }
00800     // $cols0 now contains the new widths of the constrained columns.
00801     // now need to update the $pos and $maxWidth arrays
00802     $xq=0;
00803     foreach($pos as $colName=>$p){
00804       $pos[$colName]=$xq;
00805       if (!isset($options['cols'][$colName]) || !isset($options['cols'][$colName]['width']) || $options['cols'][$colName]['width']<=0){
00806         if (isset($cols0[$colName])){
00807           $xq += $cols0[$colName] + $options['gap'];
00808           $maxWidth[$colName]=$cols0[$colName];
00809         }
00810       } else {
00811         if (isset($cols1[$colName])){
00812           $xq += $cols1[$colName];
00813         }
00814       }
00815     }
00816 
00817     $t=$x+$options['width'];
00818     $pos['_end_']=$t;
00819   }
00820 
00821   // now adjust the table to the correct location across the page
00822   switch ($options['xPos']){
00823     case 'left':
00824       $xref = $this->ez['leftMargin'];
00825       break;
00826     case 'right':
00827       $xref = $this->ez['pageWidth'] - $this->ez['rightMargin'];
00828       break;
00829     case 'centre':
00830     case 'center':
00831       $xref = $middle;
00832       break;
00833     default:
00834       $xref = $options['xPos'];
00835       break;
00836   }
00837   switch ($options['xOrientation']){
00838     case 'left':
00839       $dx = $xref-$t;
00840       break;
00841     case 'right':
00842       $dx = $xref;
00843       break;
00844     case 'centre':
00845     case 'center':
00846       $dx = $xref-$t/2;
00847       break;
00848   }
00849 
00850 
00851   foreach($pos as $k=>$v){
00852     $pos[$k]=$v+$dx;
00853   }
00854   $x0=$x+$dx;
00855   $x1=$t+$dx;
00856 
00857   $baseLeftMargin = $this->ez['leftMargin'];
00858   $basePos = $pos;
00859   $baseX0 = $x0;
00860   $baseX1 = $x1;
00861   
00862   // ok, just about ready to make me a table
00863   $this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2]);
00864   $this->setStrokeColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2]);
00865 
00866   $middle = ($x1+$x0)/2;
00867 
00868   // start a transaction which will be used to regress the table, if there are not enough rows protected
00869   if ($options['protectRows']>0){
00870     $this->transaction('start');
00871     $movedOnce=0;
00872   }
00873   $abortTable = 1;
00874   while ($abortTable){
00875   $abortTable=0;
00876 
00877   $dm = $this->ez['leftMargin']-$baseLeftMargin;
00878   foreach($basePos as $k=>$v){
00879     $pos[$k]=$v+$dm;
00880   }
00881   $x0=$baseX0+$dm;
00882   $x1=$baseX1+$dm;
00883   $middle = ($x1+$x0)/2;
00884 
00885 
00886   // if the title is set, then do that
00887   if (strlen($title)){
00888     $w = $this->getTextWidth($options['titleFontSize'],$title);
00889     $this->y -= $this->getFontHeight($options['titleFontSize']);
00890     if ($this->y < $this->ez['bottomMargin']){
00891       $this->ezNewPage();
00892         // margins may have changed on the newpage
00893         $dm = $this->ez['leftMargin']-$baseLeftMargin;
00894         foreach($basePos as $k=>$v){
00895           $pos[$k]=$v+$dm;
00896         }
00897         $x0=$baseX0+$dm;
00898         $x1=$baseX1+$dm;
00899         $middle = ($x1+$x0)/2;
00900       $this->y -= $this->getFontHeight($options['titleFontSize']);
00901     }
00902     $this->addText($middle-$w/2,$this->y,$options['titleFontSize'],$title);
00903     $this->y -= $options['titleGap'];
00904   }
00905 
00906         // margins may have changed on the newpage
00907         $dm = $this->ez['leftMargin']-$baseLeftMargin;
00908         foreach($basePos as $k=>$v){
00909           $pos[$k]=$v+$dm;
00910         }
00911         $x0=$baseX0+$dm;
00912         $x1=$baseX1+$dm;
00913   
00914   $y=$this->y; // to simplify the code a bit
00915   
00916   // make the table
00917   $height = $this->getFontHeight($options['fontSize']);
00918   $decender = $this->getFontDecender($options['fontSize']);
00919 
00920   
00921   
00922   $y0=$y+$decender;
00923   $dy=0;
00924   if ($options['showHeadings']){
00925     // this function will move the start of the table to a new page if it does not fit on this one
00926     $headingHeight = $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
00927     $y0 = $y+$headingHeight;
00928     $y1 = $y;
00929 
00930 
00931     $dm = $this->ez['leftMargin']-$baseLeftMargin;
00932     foreach($basePos as $k=>$v){
00933       $pos[$k]=$v+$dm;
00934     }
00935     $x0=$baseX0+$dm;
00936     $x1=$baseX1+$dm;
00937 
00938   } else {
00939     $y1 = $y0;
00940   }
00941   $firstLine=1;
00942 
00943   
00944   // open an object here so that the text can be put in over the shading
00945   if ($options['shaded']){
00946     $this->saveState();
00947     $textObjectId = $this->openObject();
00948     $this->closeObject();
00949     $this->addObject($textObjectId);
00950     $this->reopenObject($textObjectId);
00951   }
00952   
00953   $cnt=0;
00954   $newPage=0;
00955   foreach($data as $row){
00956     $cnt++;
00957     // the transaction support will be used to prevent rows being split
00958     if ($options['splitRows']==0){
00959       $pageStart = $this->ezPageCount;
00960       if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
00961         $columnStart = $this->ez['columns']['colNum'];
00962       }
00963       $this->transaction('start');
00964       $row_orig = $row;
00965       $y_orig = $y;
00966       $y0_orig = $y0;
00967       $y1_orig = $y1;
00968     }
00969     $ok=0;
00970     $secondTurn=0;
00971     while(!$abortTable && $ok == 0){
00972 
00973     $mx=0;
00974     $newRow=1;
00975     while(!$abortTable && ($newPage || $newRow)){
00976       
00977       $y-=$height;
00978       if ($newPage || $y<$this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y<($this->ez['bottomMargin']+$options['minRowSpace'])) ){
00979         // check that enough rows are with the heading
00980         if ($options['protectRows']>0 && $movedOnce==0 && $cnt<=$options['protectRows']){
00981           // then we need to move the whole table onto the next page
00982           $movedOnce = 1;
00983           $abortTable = 1;
00984         }
00985       
00986         $y2=$y-$mx+2*$height+$decender-$newRow*$height;
00987         if ($options['showLines']){
00988           if (!$options['showHeadings']){
00989             $y0=$y1;
00990           }
00991           $this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);
00992         }
00993         if ($options['shaded']){
00994           $this->closeObject();
00995           $this->restoreState();
00996         }
00997         $this->ezNewPage();
00998         // and the margins may have changed, this is due to the possibility of the columns being turned on
00999         // as the columns are managed by manipulating the margins
01000 
01001         $dm = $this->ez['leftMargin']-$baseLeftMargin;
01002         foreach($basePos as $k=>$v){
01003           $pos[$k]=$v+$dm;
01004         }
01005 //        $x0=$x0+$dm;
01006 //        $x1=$x1+$dm;
01007         $x0=$baseX0+$dm;
01008         $x1=$baseX1+$dm;
01009   
01010         if ($options['shaded']){
01011           $this->saveState();
01012           $textObjectId = $this->openObject();
01013           $this->closeObject();
01014           $this->addObject($textObjectId);
01015           $this->reopenObject($textObjectId);
01016         }
01017         $this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2],1);
01018         $y = $this->ez['pageHeight']-$this->ez['topMargin'];
01019         $y0=$y+$decender;
01020         $mx=0;
01021         if ($options['showHeadings']){
01022           $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
01023           $y1=$y;
01024         } else {
01025           $y1=$y0;
01026         }
01027         $firstLine=1;
01028         $y -= $height;
01029       }
01030       $newRow=0;
01031       // write the actual data
01032       // if these cells need to be split over a page, then $newPage will be set, and the remaining
01033       // text will be placed in $leftOvers
01034       $newPage=0;
01035       $leftOvers=array();
01036 
01037       foreach($cols as $colName=>$colTitle){
01038         $this->ezSetY($y+$height);
01039         $colNewPage=0;
01040         if (isset($row[$colName])){
01041           if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['link']) && strlen($options['cols'][$colName]['link'])){
01042             
01043             $lines = explode("\n",$row[$colName]);
01044             if (isset($row[$options['cols'][$colName]['link']]) && strlen($row[$options['cols'][$colName]['link']])){
01045               foreach($lines as $k=>$v){
01046                 $lines[$k]='<c:alink:'.$row[$options['cols'][$colName]['link']].'>'.$v.'</c:alink>';
01047               }
01048             }
01049           } else {
01050             $lines = explode("\n",$row[$colName]);
01051           }
01052         } else {
01053           $lines = array();
01054         }
01055         $this->y -= $options['rowGap'];
01056         foreach ($lines as $line){
01057           $line = $this->ezProcessText($line);
01058           $start=1;
01059 
01060           while (strlen($line) || $start){
01061             $start=0;
01062             if (!$colNewPage){
01063               $this->y=$this->y-$height;
01064             }
01065             if ($this->y < $this->ez['bottomMargin']){
01066   //            $this->ezNewPage();
01067               $newPage=1;  // whether a new page is required for any of the columns
01068               $colNewPage=1; // whether a new page is required for this column
01069             }
01070             if ($colNewPage){
01071               if (isset($leftOvers[$colName])){
01072                 $leftOvers[$colName].="\n".$line;
01073               } else {
01074                 $leftOvers[$colName] = $line;
01075               }
01076               $line='';
01077             } else {
01078               if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['justification']) ){
01079                 $just = $options['cols'][$colName]['justification'];
01080               } else {
01081                 $just='left';
01082               }
01083 
01084               $line=$this->addTextWrap($pos[$colName],$this->y,$maxWidth[$colName],$options['fontSize'],$line,$just);
01085             }
01086           }
01087         }
01088   
01089         $dy=$y+$height-$this->y+$options['rowGap'];
01090         if ($dy-$height*$newPage>$mx){
01091           $mx=$dy-$height*$newPage;
01092         }
01093       }
01094       // set $row to $leftOvers so that they will be processed onto the new page
01095       $row = $leftOvers;
01096       // now add the shading underneath
01097       if ($options['shaded'] && $cnt%2==0){
01098         $this->closeObject();
01099         $this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);
01100         $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
01101         $this->reopenObject($textObjectId);
01102       }
01103 
01104       if ($options['shaded']==2 && $cnt%2==1){
01105         $this->closeObject();
01106         $this->setColor($options['shadeCol2'][0],$options['shadeCol2'][1],$options['shadeCol2'][2],1);
01107         $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
01108         $this->reopenObject($textObjectId);
01109       }
01110 
01111       if ($options['showLines']>1){
01112         // then draw a line on the top of each block
01113 //        $this->closeObject();
01114         $this->saveState();
01115         $this->setStrokeColor($options['lineCol'][0],$options['lineCol'][1],$options['lineCol'][2],1);
01116 //        $this->line($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
01117         if ($firstLine){
01118           $this->setLineStyle($options['outerLineThickness']);
01119           $firstLine=0;
01120         } else {
01121           $this->setLineStyle($options['innerLineThickness']);
01122         }
01123         $this->line($x0-$options['gap']/2,$y+$decender+$height,$x1-$options['gap']/2,$y+$decender+$height);
01124         $this->restoreState();
01125 //        $this->reopenObject($textObjectId);
01126       }
01127     } // end of while 
01128     $y=$y-$mx+$height;
01129     
01130     // checking row split over pages
01131     if ($options['splitRows']==0){
01132       if ( ( ($this->ezPageCount != $pageStart) || (isset($this->ez['columns']) && $this->ez['columns']['on']==1 && $columnStart != $this->ez['columns']['colNum'] ))  && $secondTurn==0){
01133         // then we need to go back and try that again !
01134         $newPage=1;
01135         $secondTurn=1;
01136         $this->transaction('rewind');
01137         $row = $row_orig;
01138         $y = $y_orig;
01139         $y0 = $y0_orig;
01140         $y1 = $y1_orig;
01141         $ok=0;
01142 
01143         $dm = $this->ez['leftMargin']-$baseLeftMargin;
01144         foreach($basePos as $k=>$v){
01145           $pos[$k]=$v+$dm;
01146         }
01147         $x0=$baseX0+$dm;
01148         $x1=$baseX1+$dm;
01149 
01150       } else {
01151         $this->transaction('commit');
01152         $ok=1;
01153       }
01154     } else {
01155       $ok=1;  // don't go round the loop if splitting rows is allowed
01156     }
01157     
01158     }  // end of while to check for row splitting
01159     if ($abortTable){
01160       if ($ok==0){
01161         $this->transaction('abort');
01162       }
01163       // only the outer transaction should be operational
01164       $this->transaction('rewind');
01165       $this->ezNewPage();
01166       break;
01167     }
01168     
01169   } // end of foreach ($data as $row)
01170   
01171   } // end of while ($abortTable)
01172 
01173   // table has been put on the page, the rows guarded as required, commit.
01174   $this->transaction('commit');
01175 
01176   $y2=$y+$decender;
01177   if ($options['showLines']){
01178     if (!$options['showHeadings']){
01179       $y0=$y1;
01180     }
01181     $this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);
01182   }
01183 
01184   // close the object for drawing the text on top
01185   if ($options['shaded']){
01186     $this->closeObject();
01187     $this->restoreState();
01188   }
01189   
01190   $this->y=$y;
01191   return $y;
01192 }

Cezpdf::ezText text,
size = 0,
options = array(),
test = 0
 

Definition at line 1205 of file class.ezpdf.php.

References $height, $line, Cpdf::$options, $right, $size, $start, Cpdf::addTextWrap(), ezNewPage(), ezProcessText(), Cpdf::getFontHeight(), Cpdf::line(), size, and start.

Referenced by ezPrvtTableColumnHeadings().

01205                                                        {
01206   // this will add a string of text to the document, starting at the current drawing
01207   // position.
01208   // it will wrap to keep within the margins, including optional offsets from the left
01209   // and the right, if $size is not specified, then it will be the last one used, or
01210   // the default value (12 I think).
01211   // the text will go to the start of the next line when a return code "\n" is found.
01212   // possible options are:
01213   // 'left'=> number, gap to leave from the left margin
01214   // 'right'=> number, gap to leave from the right margin
01215   // 'aleft'=> number, absolute left position (overrides 'left')
01216   // 'aright'=> number, absolute right position (overrides 'right')
01217   // 'justification' => 'left','right','center','centre','full'
01218 
01219   // only set one of the next two items (leading overrides spacing)
01220   // 'leading' => number, defines the total height taken by the line, independent of the font height.
01221   // 'spacing' => a real number, though usually set to one of 1, 1.5, 2 (line spacing as used in word processing)
01222   
01223   // if $test is set then this should just check if the text is going to flow onto a new page or not, returning true or false
01224   
01225   // apply the filtering which will make the underlining function.
01226   $text = $this->ezProcessText($text);
01227   
01228   $newPage=false;
01229   $store_y = $this->y;
01230   
01231   if (is_array($options) && isset($options['aleft'])){
01232     $left=$options['aleft'];
01233   } else {
01234     $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);
01235   }
01236   if (is_array($options) && isset($options['aright'])){
01237     $right=$options['aright'];
01238   } else {
01239     $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);
01240   }
01241   if ($size<=0){
01242     $size = $this->ez['fontSize'];
01243   } else {
01244     $this->ez['fontSize']=$size;
01245   }
01246   
01247   if (is_array($options) && isset($options['justification'])){
01248     $just = $options['justification'];
01249   } else {
01250     $just = 'left';
01251   }
01252   
01253   // modifications to give leading and spacing based on those given by Craig Heydenburg 1/1/02
01254   if (is_array($options) && isset($options['leading'])) { ## use leading instead of spacing
01255     $height = $options['leading'];
01256         } else if (is_array($options) && isset($options['spacing'])) {
01257     $height = $this->getFontHeight($size) * $options['spacing'];
01258         } else {
01259                 $height = $this->getFontHeight($size);
01260         }
01261 
01262   
01263   $lines = explode("\n",$text);
01264   foreach ($lines as $line){
01265     $start=1;
01266     while (strlen($line) || $start){
01267       $start=0;
01268       $this->y=$this->y-$height;
01269       if ($this->y < $this->ez['bottomMargin']){
01270         if ($test){
01271           $newPage=true;
01272         } else {
01273           $this->ezNewPage();
01274           // and then re-calc the left and right, in case they have changed due to columns
01275         }
01276       }
01277       if (is_array($options) && isset($options['aleft'])){
01278         $left=$options['aleft'];
01279       } else {
01280         $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);
01281       }
01282       if (is_array($options) && isset($options['aright'])){
01283         $right=$options['aright'];
01284       } else {
01285         $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);
01286       }
01287       $line=$this->addTextWrap($left,$this->y,$right-$left,$size,$line,$just,0,$test);
01288     }
01289   }
01290 
01291   if ($test){
01292     $this->y=$store_y;
01293     return $newPage;
01294   } else {
01295     return $this->y;
01296   }
01297 }

Cezpdf::ezWhatPageNumber pageNum,
i = 0
 

Definition at line 299 of file class.ezpdf.php.

References $num, $start, Cpdf::addMessage(), and ezStartPageNumbers().

Referenced by Creport::rf().

00299                                         {
00300   // given a particular generic page number (ie, document numbered sequentially from beginning),
00301   // return the page number under a particular page numbering scheme ($i)
00302   $num=0;
00303   $start=1;
00304   $startNum=1;
00305   if (!isset($this->ez['pageNumbering']))
00306   {
00307     $this->addMessage('WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');
00308     return 0;
00309   }
00310   foreach($this->ez['pageNumbering'][$i] as $k=>$v){
00311     if ($k<=$pageNum){
00312       if (is_array($v)){
00313         // start block
00314         if (strlen($v['num'])){
00315           // a start was specified
00316           $start=$v['num'];
00317           $startNum=$k;
00318           $num=$pageNum-$startNum+$start;
00319         }
00320       } else {
00321         // stop block
00322         $num=0;
00323       }
00324     }
00325   }
00326   return $num;
00327 }

Cezpdf::ilink info  ) 
 

Definition at line 1469 of file class.ezpdf.php.

01469                      {
01470   $this->alink($info,1);
01471 }

Cezpdf::loadTemplate templateFile  ) 
 

Definition at line 1423 of file class.ezpdf.php.

References $code.

01423                                     {
01424   // this function will load the requested template ($file includes full or relative pathname)
01425   // the code for the template will be modified to make it name safe, and then stored in 
01426   // an array for later use
01427   // The id of the template will be returned for the user to operate on it later
01428   if (!file_exists($templateFile)){
01429     return -1;
01430   }
01431 
01432   $code = implode('',file($templateFile));
01433   if (!strlen($code)){
01434     return;
01435   }
01436 
01437   $code = trim($code);
01438   if (substr($code,0,5)=='<?php'){
01439     $code = substr($code,5);
01440   }
01441   if (substr($code,-2)=='?>'){
01442     $code = substr($code,0,strlen($code)-2);
01443   }
01444   if (isset($this->ez['numTemplates'])){
01445     $newNum = $this->ez['numTemplates'];
01446     $this->ez['numTemplates']++;
01447   } else {
01448     $newNum=0;
01449     $this->ez['numTemplates']=1;
01450     $this->ez['templates']=array();
01451   }
01452 
01453   $this->ez['templates'][$newNum]['code']=$code;
01454 
01455   return $newNum;
01456 }

Cezpdf::uline info  ) 
 

Definition at line 1518 of file class.ezpdf.php.

References $a, $i, $start, and start.

01518                      {
01519   // a callback function to support underlining
01520   $lineFactor=0.05; // the thickness of the line as a proportion of the height. also the drop of the line.
01521   switch($info['status']){
01522     case 'start':
01523     case 'sol':
01524     
01525       // the beginning of the underline zone
01526       if (!isset($this->ez['links'])){
01527         $this->ez['links']=array();
01528       }
01529       $i = $info['nCallback'];
01530       $this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height']);
01531       $this->saveState();
01532       $thick = $info['height']*$lineFactor;
01533       $this->setLineStyle($thick);
01534       break;
01535     case 'end':
01536     case 'eol':
01537       // the end of the link
01538       // assume that it is the most recent opening which has closed
01539       $i = $info['nCallback'];
01540       $start = $this->ez['links'][$i];
01541       // add underlining
01542       $a = deg2rad((float)$start['angle']-90.0);
01543       $drop = $start['height']*$lineFactor*1.5;
01544       $dropx = cos($a)*$drop;
01545       $dropy = -sin($a)*$drop;
01546       $this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);
01547       $this->restoreState();
01548       break;
01549   }
01550 }


Field Documentation

Cezpdf::$ez = array('fontSize'=>10)
 

Definition at line 21 of file class.ezpdf.php.

Cezpdf::$ezPageCount = 0
 

Definition at line 24 of file class.ezpdf.php.

Cezpdf::$ezPages = array()
 

Definition at line 23 of file class.ezpdf.php.

Cezpdf::$y
 

Definition at line 22 of file class.ezpdf.php.

Referenced by ezPrvtTableColumnHeadings(), ezSetY(), and ezTable().


The documentation for this class was generated from the following file: