12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568 |
- <?php
- include_once('class.pdf.php');
- class Cezpdf extends Cpdf {
- var $ez=array('fontSize'=>10);
- var $y;
- var $ezPages=array();
- var $ezPageCount=0;
- function Cezpdf($paper='a4',$orientation='portrait'){
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!is_array($paper)){
- switch (strtoupper($paper)){
- case '4A0': {$size = array(0,0,4767.87,6740.79); break;}
- case '2A0': {$size = array(0,0,3370.39,4767.87); break;}
- case 'A0': {$size = array(0,0,2383.94,3370.39); break;}
- case 'A1': {$size = array(0,0,1683.78,2383.94); break;}
- case 'A2': {$size = array(0,0,1190.55,1683.78); break;}
- case 'A3': {$size = array(0,0,841.89,1190.55); break;}
- case 'A4': default: {$size = array(0,0,595.28,841.89); break;}
- case 'A5': {$size = array(0,0,419.53,595.28); break;}
- case 'A6': {$size = array(0,0,297.64,419.53); break;}
- case 'A7': {$size = array(0,0,209.76,297.64); break;}
- case 'A8': {$size = array(0,0,147.40,209.76); break;}
- case 'A9': {$size = array(0,0,104.88,147.40); break;}
- case 'A10': {$size = array(0,0,73.70,104.88); break;}
- case 'B0': {$size = array(0,0,2834.65,4008.19); break;}
- case 'B1': {$size = array(0,0,2004.09,2834.65); break;}
- case 'B2': {$size = array(0,0,1417.32,2004.09); break;}
- case 'B3': {$size = array(0,0,1000.63,1417.32); break;}
- case 'B4': {$size = array(0,0,708.66,1000.63); break;}
- case 'B5': {$size = array(0,0,498.90,708.66); break;}
- case 'B6': {$size = array(0,0,354.33,498.90); break;}
- case 'B7': {$size = array(0,0,249.45,354.33); break;}
- case 'B8': {$size = array(0,0,175.75,249.45); break;}
- case 'B9': {$size = array(0,0,124.72,175.75); break;}
- case 'B10': {$size = array(0,0,87.87,124.72); break;}
- case 'C0': {$size = array(0,0,2599.37,3676.54); break;}
- case 'C1': {$size = array(0,0,1836.85,2599.37); break;}
- case 'C2': {$size = array(0,0,1298.27,1836.85); break;}
- case 'C3': {$size = array(0,0,918.43,1298.27); break;}
- case 'C4': {$size = array(0,0,649.13,918.43); break;}
- case 'C5': {$size = array(0,0,459.21,649.13); break;}
- case 'C6': {$size = array(0,0,323.15,459.21); break;}
- case 'C7': {$size = array(0,0,229.61,323.15); break;}
- case 'C8': {$size = array(0,0,161.57,229.61); break;}
- case 'C9': {$size = array(0,0,113.39,161.57); break;}
- case 'C10': {$size = array(0,0,79.37,113.39); break;}
- case 'RA0': {$size = array(0,0,2437.80,3458.27); break;}
- case 'RA1': {$size = array(0,0,1729.13,2437.80); break;}
- case 'RA2': {$size = array(0,0,1218.90,1729.13); break;}
- case 'RA3': {$size = array(0,0,864.57,1218.90); break;}
- case 'RA4': {$size = array(0,0,609.45,864.57); break;}
- case 'SRA0': {$size = array(0,0,2551.18,3628.35); break;}
- case 'SRA1': {$size = array(0,0,1814.17,2551.18); break;}
- case 'SRA2': {$size = array(0,0,1275.59,1814.17); break;}
- case 'SRA3': {$size = array(0,0,907.09,1275.59); break;}
- case 'SRA4': {$size = array(0,0,637.80,907.09); break;}
- case 'LETTER': {$size = array(0,0,612.00,792.00); break;}
- case 'LEGAL': {$size = array(0,0,612.00,1008.00); break;}
- case 'EXECUTIVE': {$size = array(0,0,521.86,756.00); break;}
- case 'FOLIO': {$size = array(0,0,612.00,936.00); break;}
- }
- switch (strtolower($orientation)){
- case 'landscape':
- $a=$size[3];
- $size[3]=$size[2];
- $size[2]=$a;
- break;
- }
- } else {
- if (count($paper)>2) {
-
- $size = $paper;
- }
- else {
- $size[0] = 0;
- $size[1] = 0;
- $size[2] = ( $paper[0] / 2.54 ) * 72;
- $size[3] = ( $paper[1] / 2.54 ) * 72;
- }
- }
- $this->Cpdf($size);
- $this->ez['pageWidth']=$size[2];
- $this->ez['pageHeight']=$size[3];
-
- $this->ez['topMargin']=30;
- $this->ez['bottomMargin']=30;
- $this->ez['leftMargin']=30;
- $this->ez['rightMargin']=30;
-
- $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
-
- $this->ezPages[1]=$this->getFirstPageId();
- $this->ezPageCount=1;
- }
- function ezSetCmMargins($top,$bottom,$left,$right){
- $top = ( $top / 2.54 ) * 72;
- $bottom = ( $bottom / 2.54 ) * 72;
- $left = ( $left / 2.54 ) * 72;
- $right = ( $right / 2.54 ) * 72;
- $this->ezSetMargins($top,$bottom,$left,$right);
- }
- function ezColumnsStart($options=array()){
-
- if (isset($this->ez['columns']) && $this->ez['columns']==1){
-
- return;
- }
- $def=array('gap'=>10,'num'=>2);
- foreach($def as $k=>$v){
- if (!isset($options[$k])){
- $options[$k]=$v;
- }
- }
-
- $this->ez['columns']=array('on'=>1,'colNum'=>1);
-
- $this->ez['columns']['margins']=array(
- $this->ez['leftMargin']
- ,$this->ez['rightMargin']
- ,$this->ez['topMargin']
- ,$this->ez['bottomMargin']
- );
-
- $this->ez['columns']['options']=$options;
-
-
- $this->ez['topMargin']=$this->ez['pageHeight']-$this->y;
- $width=($this->ez['pageWidth']-$this->ez['leftMargin']-$this->ez['rightMargin']-($options['num']-1)*$options['gap'])/$options['num'];
- $this->ez['columns']['width']=$width;
- $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;
- }
- function ezColumnsStop(){
- if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
- $this->ez['columns']['on']=0;
- $this->ez['leftMargin']=$this->ez['columns']['margins'][0];
- $this->ez['rightMargin']=$this->ez['columns']['margins'][1];
- $this->ez['topMargin']=$this->ez['columns']['margins'][2];
- $this->ez['bottomMargin']=$this->ez['columns']['margins'][3];
- }
- }
- function ezInsertMode($status=1,$pageNum=1,$pos='before'){
-
-
- switch($status){
- case '1':
- if (isset($this->ezPages[$pageNum])){
- $this->ez['insertMode']=1;
- $this->ez['insertOptions']=array('id'=>$this->ezPages[$pageNum],'pos'=>$pos);
- }
- break;
- case '0':
- $this->ez['insertMode']=0;
- break;
- }
- }
- function ezNewPage(){
- $pageRequired=1;
- if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
-
-
- $this->ez['columns']['colNum']++;
- if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num']){
-
- $pageRequired=0;
- } else {
- $this->ez['columns']['colNum']=1;
- $this->ez['topMargin']=$this->ez['columns']['margins'][2];
- }
- $width = $this->ez['columns']['width'];
- $this->ez['leftMargin']=$this->ez['columns']['margins'][0]+($this->ez['columns']['colNum']-1)*($this->ez['columns']['options']['gap']+$width);
- $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;
- }
- if ($pageRequired){
-
- $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
-
- $this->ezPageCount++;
- if (isset($this->ez['insertMode']) && $this->ez['insertMode']==1){
- $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1,$this->ez['insertOptions']['id'],$this->ez['insertOptions']['pos']);
-
- $this->ez['insertOptions']['id']=$id;
- $this->ez['insertOptions']['pos']='after';
- } else {
- $this->ezPages[$this->ezPageCount] = $this->newPage();
- }
- } else {
- $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
- }
- }
- function ezSetMargins($top,$bottom,$left,$right){
-
- $this->ez['topMargin']=$top;
- $this->ez['bottomMargin']=$bottom;
- $this->ez['leftMargin']=$left;
- $this->ez['rightMargin']=$right;
-
-
- if ($this->y > $this->ez['pageHeight']-$top){
-
- $this->y = $this->ez['pageHeight']-$top;
- }
- if ( $this->y < $bottom){
-
- $this->ezNewPage();
- }
- }
- function ezGetCurrentPageNumber(){
-
- return $this->ezPageCount;
- }
- function ezStartPageNumbers($x,$y,$size,$pos='left',$pattern='{PAGENUM} of {TOTALPAGENUM}',$num=''){
-
-
-
-
-
-
-
-
-
- if (!$pos || !strlen($pos)){
- $pos='left';
- }
- if (!$pattern || !strlen($pattern)){
- $pattern='{PAGENUM} of {TOTALPAGENUM}';
- }
- if (!isset($this->ez['pageNumbering'])){
- $this->ez['pageNumbering']=array();
- }
- $i = count($this->ez['pageNumbering']);
- $this->ez['pageNumbering'][$i][$this->ezPageCount]=array('x'=>$x,'y'=>$y,'pos'=>$pos,'pattern'=>$pattern,'num'=>$num,'size'=>$size);
- return $i;
- }
- function ezWhatPageNumber($pageNum,$i=0){
-
-
- $num=0;
- $start=1;
- $startNum=1;
- if (!isset($this->ez['pageNumbering']))
- {
- $this->addMessage('WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');
- return 0;
- }
- foreach($this->ez['pageNumbering'][$i] as $k=>$v){
- if ($k<=$pageNum){
- if (is_array($v)){
-
- if (strlen($v['num'])){
-
- $start=$v['num'];
- $startNum=$k;
- $num=$pageNum-$startNum+$start;
- }
- } else {
-
- $num=0;
- }
- }
- }
- return $num;
- }
- function ezStopPageNumbers($stopTotal=0,$next=0,$i=0){
-
-
-
- if (!isset($this->ez['pageNumbering'])){
- $this->ez['pageNumbering']=array();
- }
- if ($next && isset($this->ez['pageNumbering'][$i][$this->ezPageCount]) && is_array($this->ez['pageNumbering'][$i][$this->ezPageCount])){
-
-
- if ($stopTotal){
- $this->ez['pageNumbering'][$i][$this->ezPageCount]['stoptn']=1;
- } else {
- $this->ez['pageNumbering'][$i][$this->ezPageCount]['stopn']=1;
- }
- } else {
- if ($stopTotal){
- $this->ez['pageNumbering'][$i][$this->ezPageCount]='stopt';
- } else {
- $this->ez['pageNumbering'][$i][$this->ezPageCount]='stop';
- }
- if ($next){
- $this->ez['pageNumbering'][$i][$this->ezPageCount].='n';
- }
- }
- }
- function ezPRVTpageNumberSearch($lbl,&$tmp){
- foreach($tmp as $i=>$v){
- if (is_array($v)){
- if (isset($v[$lbl])){
- return $i;
- }
- } else {
- if ($v==$lbl){
- return $i;
- }
- }
- }
- return 0;
- }
- function ezPRVTaddPageNumbers(){
-
- if (isset($this->ez['pageNumbering'])){
- $totalPages1 = $this->ezPageCount;
- $tmp1=$this->ez['pageNumbering'];
- $status=0;
- foreach($tmp1 as $i=>$tmp){
-
-
- $k = $this->ezPRVTpageNumberSearch('stopt',$tmp);
- if ($k && $k>0){
- $totalPages = $k-1;
- } else {
- $l = $this->ezPRVTpageNumberSearch('stoptn',$tmp);
- if ($l && $l>0){
- $totalPages = $l;
- } else {
- $totalPages = $totalPages1;
- }
- }
- foreach ($this->ezPages as $pageNum=>$id){
- if (isset($tmp[$pageNum])){
- if (is_array($tmp[$pageNum])){
-
- $status=1;
- $info = $tmp[$pageNum];
- $info['dnum']=$info['num']-$pageNum;
-
- if (isset($info['stopn']) || isset($info['stoptn']) ){
- $status=2;
- }
- } else if ($tmp[$pageNum]=='stop' || $tmp[$pageNum]=='stopt'){
-
- $status=0;
- } else if ($status==1 && ($tmp[$pageNum]=='stoptn' || $tmp[$pageNum]=='stopn')){
-
- $status=2;
- }
- }
- if ($status){
-
- if (strlen($info['num'])){
- $num=$pageNum+$info['dnum'];
- } else {
- $num=$pageNum;
- }
- $total = $totalPages+$num-$pageNum;
- $pat = str_replace('{PAGENUM}',$num,$info['pattern']);
- $pat = str_replace('{TOTALPAGENUM}',$total,$pat);
- $this->reopenObject($id);
- switch($info['pos']){
- case 'right':
- $this->addText($info['x'],$info['y'],$info['size'],$pat);
- break;
- default:
- $w=$this->getTextWidth($info['size'],$pat);
- $this->addText($info['x']-$w,$info['y'],$info['size'],$pat);
- break;
- }
- $this->closeObject();
- }
- if ($status==2){
- $status=0;
- }
- }
- }
- }
- }
- function ezPRVTcleanUp(){
- $this->ezPRVTaddPageNumbers();
- }
- function ezStream($options=''){
- $this->ezPRVTcleanUp();
- $this->stream($options);
- }
- function ezOutput($options=0){
- $this->ezPRVTcleanUp();
- return $this->output($options);
- }
- function ezSetY($y){
-
- $this->y = $y;
- if ( $this->y < $this->ez['bottomMargin']){
-
- $this->ezNewPage();
- }
- }
- function ezSetDy($dy,$mod=''){
-
-
-
-
-
- $this->y += $dy;
- if ( $this->y < $this->ez['bottomMargin']){
-
- $this->ezNewPage();
- if ($mod=='makeSpace'){
- $this->y += $dy;
- }
- }
- }
- function ezPrvtTableDrawLines($pos,$gap,$x0,$x1,$y0,$y1,$y2,$col,$inner,$outer,$opt=1){
- $x0=1000;
- $x1=0;
- $this->setStrokeColor($col[0],$col[1],$col[2]);
- $cnt=0;
- $n = count($pos);
- foreach($pos as $x){
- $cnt++;
- if ($cnt==1 || $cnt==$n){
- $this->setLineStyle($outer);
- } else {
- $this->setLineStyle($inner);
- }
- $this->line($x-$gap/2,$y0,$x-$gap/2,$y2);
- if ($x>$x1){ $x1=$x; };
- if ($x<$x0){ $x0=$x; };
- }
- $this->setLineStyle($outer);
- $this->line($x0-$gap/2-$outer/2,$y0,$x1-$gap/2+$outer/2,$y0);
-
-
- if ($y0!=$y1 && $opt<2){
- $this->line($x0-$gap/2,$y1,$x1-$gap/2,$y1);
- }
- $this->line($x0-$gap/2-$outer/2,$y2,$x1-$gap/2+$outer/2,$y2);
- }
- function ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$gap,$size,&$y,$optionsAll=array()){
-
-
-
- if (isset($optionsAll['cols'])){
- $options = $optionsAll['cols'];
- } else {
- $options = array();
- }
- $mx=0;
- $startPage = $this->ezPageCount;
- $secondGo=0;
-
-
-
-
-
- $this->transaction('start');
- $ok=0;
- $y-=$gap;
- while ($ok==0){
- foreach($cols as $colName=>$colHeading){
- $this->ezSetY($y);
- if (isset($options[$colName]) && isset($options[$colName]['justification'])){
- $justification = $options[$colName]['justification'];
- } else {
- $justification = 'left';
- }
- $this->ezText($colHeading,$size,array('aleft'=> $pos[$colName],'aright'=>($maxWidth[$colName]+$pos[$colName]),'justification'=>$justification));
- $dy = $y-$this->y;
- if ($dy>$mx){
- $mx=$dy;
- }
- }
- $y = $y - $mx - $gap + $decender;
-
-
- if ($this->ezPageCount != $startPage && $secondGo==0){
- $this->transaction('rewind');
- $this->ezNewPage();
- $y = $this->y - $gap-$decender;
- $ok=0;
- $secondGo=1;
- $mx=0;
- } else {
- $this->transaction('commit');
- $ok=1;
- }
- }
- return $mx+$gap*2-$decender;
- }
- function ezPrvtGetTextWidth($size,$text){
-
-
- $mx=0;
- $lines = explode("\n",$text);
- foreach ($lines as $line){
- $w = $this->getTextWidth($size,$line);
- if ($w>$mx){
- $mx=$w;
- }
- }
- return $mx;
- }
- function ezTable(&$data,$cols='',$title='',$options=''){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!is_array($data)){
- return;
- }
- if (!is_array($cols)){
-
- reset($data);
- list($k,$v)=each($data);
- if (!is_array($v)){
- return;
- }
- $cols=array();
- foreach($v as $k1=>$v1){
- $cols[$k1]=$k1;
- }
- }
- if (!is_array($options)){
- $options=array();
- }
- $defaults = array(
- 'shaded'=>1,'showLines'=>1,'shadeCol'=>array(0.8,0.8,0.8),'shadeCol2'=>array(0.7,0.7,0.7),'fontSize'=>10,'titleFontSize'=>12
- ,'titleGap'=>5,'lineCol'=>array(0,0,0),'gap'=>5,'xPos'=>'centre','xOrientation'=>'centre'
- ,'showHeadings'=>1,'textCol'=>array(0,0,0),'width'=>0,'maxWidth'=>0,'cols'=>array(),'minRowSpace'=>-100,'rowGap'=>2,'colGap'=>5
- ,'innerLineThickness'=>1,'outerLineThickness'=>1,'splitRows'=>0,'protectRows'=>1
- );
- foreach($defaults as $key=>$value){
- if (is_array($value)){
- if (!isset($options[$key]) || !is_array($options[$key])){
- $options[$key]=$value;
- }
- } else {
- if (!isset($options[$key])){
- $options[$key]=$value;
- }
- }
- }
- $options['gap']=2*$options['colGap'];
- $middle = ($this->ez['pageWidth']-$this->ez['rightMargin'])/2+($this->ez['leftMargin'])/2;
-
- $maxWidth=array();
- foreach($cols as $colName=>$colHeading){
- $maxWidth[$colName]=0;
- }
-
- foreach($data as $row){
- foreach($cols as $colName=>$colHeading){
- $w = $this->ezPrvtGetTextWidth($options['fontSize'],(string)$row[$colName])*1.01;
- if ($w > $maxWidth[$colName]){
- $maxWidth[$colName]=$w;
- }
- }
- }
-
- foreach($cols as $colName=>$colTitle){
- $w = $this->ezPrvtGetTextWidth($options['fontSize'],(string)$colTitle)*1.01;
- if ($w > $maxWidth[$colName]){
- $maxWidth[$colName]=$w;
- }
- }
-
- $pos=array();
- $x=0;
- $t=$x;
- $adjustmentWidth=0;
- $setWidth=0;
- foreach($maxWidth as $colName => $w){
- $pos[$colName]=$t;
-
-
- if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['width']) && $options['cols'][$colName]['width']>0){
- $t=$t+$options['cols'][$colName]['width'];
- $maxWidth[$colName] = $options['cols'][$colName]['width']-$options['gap'];
- $setWidth += $options['cols'][$colName]['width'];
- } else {
- $t=$t+$w+$options['gap'];
- $adjustmentWidth += $w;
- $setWidth += $options['gap'];
- }
- }
- $pos['_end_']=$t;
-
-
- if ($options['width']==0 && $options['maxWidth'] && ($t-$x)>$options['maxWidth']){
-
- $options['width']=$options['maxWidth'];
- }
- if ($options['width'] && $adjustmentWidth>0 && $setWidth<$options['width']){
-
- $cols0 = array();
- $cols1 = array();
- $xq=0;
- $presentWidth=0;
- $last='';
- foreach($pos as $colName=>$p){
- if (!isset($options['cols'][$last]) || !isset($options['cols'][$last]['width']) || $options['cols'][$last]['width']<=0){
- if (strlen($last)){
- $cols0[$last]=$p-$xq -$options['gap'];
- $presentWidth += ($p-$xq - $options['gap']);
- }
- } else {
- $cols1[$last]=$p-$xq;
- }
- $last=$colName;
- $xq=$p;
- }
-
- $neededWidth = $options['width']-$setWidth;
-
- if ($presentWidth<$neededWidth){
- foreach($cols0 as $colName=>$w){
- $cols0[$colName]+= ($neededWidth-$presentWidth)/count($cols0);
- }
- } else {
- $cnt=0;
- while ($presentWidth>$neededWidth && $cnt<100){
- $cnt++;
-
- $aWidest = array();
- $nWidest=0;
- $widest=0;
- foreach($cols0 as $colName=>$w){
- if ($w>$widest){
- $aWidest=array($colName);
- $nWidest = $widest;
- $widest=$w;
- } else if ($w==$widest){
- $aWidest[]=$colName;
- }
- }
-
- $newWidestWidth = $widest - ($presentWidth-$neededWidth)/count($aWidest);
- if ($newWidestWidth > $nWidest){
-
- foreach($aWidest as $colName){
- $cols0[$colName] = $newWidestWidth;
- }
- $presentWidth=$neededWidth;
- } else {
-
-
- foreach($aWidest as $colName){
- $cols0[$colName] = $nWidest;
- }
- $presentWidth=$presentWidth-($widest-$nWidest)*count($aWidest);
- }
- }
- }
-
-
- $xq=0;
- foreach($pos as $colName=>$p){
- $pos[$colName]=$xq;
- if (!isset($options['cols'][$colName]) || !isset($options['cols'][$colName]['width']) || $options['cols'][$colName]['width']<=0){
- if (isset($cols0[$colName])){
- $xq += $cols0[$colName] + $options['gap'];
- $maxWidth[$colName]=$cols0[$colName];
- }
- } else {
- if (isset($cols1[$colName])){
- $xq += $cols1[$colName];
- }
- }
- }
- $t=$x+$options['width'];
- $pos['_end_']=$t;
- }
-
- switch ($options['xPos']){
- case 'left':
- $xref = $this->ez['leftMargin'];
- break;
- case 'right':
- $xref = $this->ez['pageWidth'] - $this->ez['rightMargin'];
- break;
- case 'centre':
- case 'center':
- $xref = $middle;
- break;
- default:
- $xref = $options['xPos'];
- break;
- }
- switch ($options['xOrientation']){
- case 'left':
- $dx = $xref-$t;
- break;
- case 'right':
- $dx = $xref;
- break;
- case 'centre':
- case 'center':
- $dx = $xref-$t/2;
- break;
- }
- foreach($pos as $k=>$v){
- $pos[$k]=$v+$dx;
- }
- $x0=$x+$dx;
- $x1=$t+$dx;
- $baseLeftMargin = $this->ez['leftMargin'];
- $basePos = $pos;
- $baseX0 = $x0;
- $baseX1 = $x1;
-
- $this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2]);
- $this->setStrokeColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2]);
- $middle = ($x1+$x0)/2;
-
- if ($options['protectRows']>0){
- $this->transaction('start');
- $movedOnce=0;
- }
- $abortTable = 1;
- while ($abortTable){
- $abortTable=0;
- $dm = $this->ez['leftMargin']-$baseLeftMargin;
- foreach($basePos as $k=>$v){
- $pos[$k]=$v+$dm;
- }
- $x0=$baseX0+$dm;
- $x1=$baseX1+$dm;
- $middle = ($x1+$x0)/2;
-
- if (strlen($title)){
- $w = $this->getTextWidth($options['titleFontSize'],$title);
- $this->y -= $this->getFontHeight($options['titleFontSize']);
- if ($this->y < $this->ez['bottomMargin']){
- $this->ezNewPage();
-
- $dm = $this->ez['leftMargin']-$baseLeftMargin;
- foreach($basePos as $k=>$v){
- $pos[$k]=$v+$dm;
- }
- $x0=$baseX0+$dm;
- $x1=$baseX1+$dm;
- $middle = ($x1+$x0)/2;
- $this->y -= $this->getFontHeight($options['titleFontSize']);
- }
- $this->addText($middle-$w/2,$this->y,$options['titleFontSize'],$title);
- $this->y -= $options['titleGap'];
- }
-
- $dm = $this->ez['leftMargin']-$baseLeftMargin;
- foreach($basePos as $k=>$v){
- $pos[$k]=$v+$dm;
- }
- $x0=$baseX0+$dm;
- $x1=$baseX1+$dm;
- $y=$this->y;
-
- $height = $this->getFontHeight($options['fontSize']);
- $decender = $this->getFontDecender($options['fontSize']);
- $y0=$y+$decender;
- $dy=0;
- if ($options['showHeadings']){
-
- $headingHeight = $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
- $y0 = $y+$headingHeight;
- $y1 = $y;
- $dm = $this->ez['leftMargin']-$baseLeftMargin;
- foreach($basePos as $k=>$v){
- $pos[$k]=$v+$dm;
- }
- $x0=$baseX0+$dm;
- $x1=$baseX1+$dm;
- } else {
- $y1 = $y0;
- }
- $firstLine=1;
-
- if ($options['shaded']){
- $this->saveState();
- $textObjectId = $this->openObject();
- $this->closeObject();
- $this->addObject($textObjectId);
- $this->reopenObject($textObjectId);
- }
- $cnt=0;
- $newPage=0;
- foreach($data as $row){
- $cnt++;
-
- if ($options['splitRows']==0){
- $pageStart = $this->ezPageCount;
- if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
- $columnStart = $this->ez['columns']['colNum'];
- }
- $this->transaction('start');
- $row_orig = $row;
- $y_orig = $y;
- $y0_orig = $y0;
- $y1_orig = $y1;
- }
- $ok=0;
- $secondTurn=0;
- while(!$abortTable && $ok == 0){
- $mx=0;
- $newRow=1;
- while(!$abortTable && ($newPage || $newRow)){
- $y-=$height;
- if ($newPage || $y<$this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y<($this->ez['bottomMargin']+$options['minRowSpace'])) ){
-
- if ($options['protectRows']>0 && $movedOnce==0 && $cnt<=$options['protectRows']){
-
- $movedOnce = 1;
- $abortTable = 1;
- }
- $y2=$y-$mx+2*$height+$decender-$newRow*$height;
- if ($options['showLines']){
- if (!$options['showHeadings']){
- $y0=$y1;
- }
- $this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);
- }
- if ($options['shaded']){
- $this->closeObject();
- $this->restoreState();
- }
- $this->ezNewPage();
-
-
- $dm = $this->ez['leftMargin']-$baseLeftMargin;
- foreach($basePos as $k=>$v){
- $pos[$k]=$v+$dm;
- }
- $x0=$baseX0+$dm;
- $x1=$baseX1+$dm;
- if ($options['shaded']){
- $this->saveState();
- $textObjectId = $this->openObject();
- $this->closeObject();
- $this->addObject($textObjectId);
- $this->reopenObject($textObjectId);
- }
- $this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2],1);
- $y = $this->ez['pageHeight']-$this->ez['topMargin'];
- $y0=$y+$decender;
- $mx=0;
- if ($options['showHeadings']){
- $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
- $y1=$y;
- } else {
- $y1=$y0;
- }
- $firstLine=1;
- $y -= $height;
- }
- $newRow=0;
-
-
-
- $newPage=0;
- $leftOvers=array();
- foreach($cols as $colName=>$colTitle){
- $this->ezSetY($y+$height);
- $colNewPage=0;
- if (isset($row[$colName])){
- if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['link']) && strlen($options['cols'][$colName]['link'])){
- $lines = explode("\n",$row[$colName]);
- if (isset($row[$options['cols'][$colName]['link']]) && strlen($row[$options['cols'][$colName]['link']])){
- foreach($lines as $k=>$v){
- $lines[$k]='<c:alink:'.$row[$options['cols'][$colName]['link']].'>'.$v.'</c:alink>';
- }
- }
- } else {
- $lines = explode("\n",$row[$colName]);
- }
- } else {
- $lines = array();
- }
- $this->y -= $options['rowGap'];
- foreach ($lines as $line){
- $line = $this->ezProcessText($line);
- $start=1;
- while (strlen($line) || $start){
- $start=0;
- if (!$colNewPage){
- $this->y=$this->y-$height;
- }
- if ($this->y < $this->ez['bottomMargin']){
-
- $newPage=1;
- $colNewPage=1;
- }
- if ($colNewPage){
- if (isset($leftOvers[$colName])){
- $leftOvers[$colName].="\n".$line;
- } else {
- $leftOvers[$colName] = $line;
- }
- $line='';
- } else {
- if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['justification']) ){
- $just = $options['cols'][$colName]['justification'];
- } else {
- $just='left';
- }
- $line=$this->addTextWrap($pos[$colName],$this->y,$maxWidth[$colName],$options['fontSize'],$line,$just);
- }
- }
- }
- $dy=$y+$height-$this->y+$options['rowGap'];
- if ($dy-$height*$newPage>$mx){
- $mx=$dy-$height*$newPage;
- }
- }
-
- $row = $leftOvers;
-
- if ($options['shaded'] && $cnt%2==0){
- $this->closeObject();
- $this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);
- $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
- $this->reopenObject($textObjectId);
- }
- if ($options['shaded']==2 && $cnt%2==1){
- $this->closeObject();
- $this->setColor($options['shadeCol2'][0],$options['shadeCol2'][1],$options['shadeCol2'][2],1);
- $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
- $this->reopenObject($textObjectId);
- }
- if ($options['showLines']>1){
-
- $this->saveState();
- $this->setStrokeColor($options['lineCol'][0],$options['lineCol'][1],$options['lineCol'][2],1);
- if ($firstLine){
- $this->setLineStyle($options['outerLineThickness']);
- $firstLine=0;
- } else {
- $this->setLineStyle($options['innerLineThickness']);
- }
- $this->line($x0-$options['gap']/2,$y+$decender+$height,$x1-$options['gap']/2,$y+$decender+$height);
- $this->restoreState();
- }
- }
- $y=$y-$mx+$height;
-
- if ($options['splitRows']==0){
- if ( ( ($this->ezPageCount != $pageStart) || (isset($this->ez['columns']) && $this->ez['columns']['on']==1 && $columnStart != $this->ez['columns']['colNum'] )) && $secondTurn==0){
-
- $newPage=1;
- $secondTurn=1;
- $this->transaction('rewind');
- $row = $row_orig;
- $y = $y_orig;
- $y0 = $y0_orig;
- $y1 = $y1_orig;
- $ok=0;
- $dm = $this->ez['leftMargin']-$baseLeftMargin;
- foreach($basePos as $k=>$v){
- $pos[$k]=$v+$dm;
- }
- $x0=$baseX0+$dm;
- $x1=$baseX1+$dm;
- } else {
- $this->transaction('commit');
- $ok=1;
- }
- } else {
- $ok=1;
- }
- }
- if ($abortTable){
- if ($ok==0){
- $this->transaction('abort');
- }
-
- $this->transaction('rewind');
- $this->ezNewPage();
- break;
- }
- }
- }
-
- $this->transaction('commit');
- $y2=$y+$decender;
- if ($options['showLines']){
- if (!$options['showHeadings']){
- $y0=$y1;
- }
- $this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);
- }
-
- if ($options['shaded']){
- $this->closeObject();
- $this->restoreState();
- }
- $this->y=$y;
- return $y;
- }
- function ezProcessText($text){
-
-
- $search = array('<u>','<U>','</u>','</U>');
- $replace = array('<c:uline>','<c:uline>','</c:uline>','</c:uline>');
- return str_replace($search,$replace,$text);
- }
- function ezText($text,$size=0,$options=array(),$test=0){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $text = $this->ezProcessText($text);
- $newPage=false;
- $store_y = $this->y;
- if (is_array($options) && isset($options['aleft'])){
- $left=$options['aleft'];
- } else {
- $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);
- }
- if (is_array($options) && isset($options['aright'])){
- $right=$options['aright'];
- } else {
- $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);
- }
- if ($size<=0){
- $size = $this->ez['fontSize'];
- } else {
- $this->ez['fontSize']=$size;
- }
- if (is_array($options) && isset($options['justification'])){
- $just = $options['justification'];
- } else {
- $just = 'left';
- }
-
- if (is_array($options) && isset($options['leading'])) {
- $height = $options['leading'];
- } else if (is_array($options) && isset($options['spacing'])) {
- $height = $this->getFontHeight($size) * $options['spacing'];
- } else {
- $height = $this->getFontHeight($size);
- }
- $lines = explode("\n",$text);
- foreach ($lines as $line)
- {
-
- $start=1;
- while (strlen($line) || $start)
- {
-
- $start=0;
- $this->y=$this->y-$height;
- if ($this->y < $this->ez['bottomMargin'])
- {
-
- if ($test)
- {
-
- $newPage=true;
- }
- else
- {
-
- $this->ezNewPage();
-
- }
- }
- if (is_array($options) && isset($options['aleft'])){
-
- $left=$options['aleft'];
- } else {
-
- $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);
- }
- if (is_array($options) && isset($options['aright'])){
- $right=$options['aright'];
- } else {
- $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);
- }
- $line=$this->addTextWrap($left,$this->y,$right-$left,$size,$line,$just,0,$test);
- }
- }
- if ($test){
- $this->y=$store_y;
- return $newPage;
- } else {
- return $this->y;
- }
- }
- function ezImage($image,$pad = 5,$width = 0,$resize = 'full',$just = 'center',$border = ''){
-
- if (stristr($image,'://'))
- {
- $fp = @fopen($image,"rb");
- while(!feof($fp))
- {
- $cont.= fread($fp,1024);
- }
- fclose($fp);
- $image = tempnam ("/tmp", "php-pdf");
- $fp2 = @fopen($image,"w");
- fwrite($fp2,$cont);
- fclose($fp2);
- $temp = true;
- }
- if (!(file_exists($image))) return false;
- $imageInfo = getimagesize($image);
- switch ($imageInfo[2]){
- case 2:
- $type = "jpeg";
- break;
- case 3:
- $type = "png";
- break;
- default:
- return false;
- }
- if ($width == 0) $width = $imageInfo[0];
- $ratio = $imageInfo[0]/$imageInfo[1];
-
- if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
- {
- $bigwidth = $this->ez['columns']['width'] - ($pad * 2);
- }
- else
- {
- $bigwidth = $this->ez['pageWidth'] - ($pad * 2);
- }
-
- if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)
- {
- $width = $bigwidth;
- }
- $height = ($width/$ratio);
-
- if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))
- {
- if ($resize != 'full')
- {
- $this->ezNewPage();
- }
- else
- {
- $height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2));
- $width = ($height*$ratio);
- }
- }
-
- if ($width < $bigwidth)
- {
-
- if ($just == 'center')
- {
- $offset = ($bigwidth - $width) / 2;
- }
-
- if ($just == 'right')
- {
- $offset = ($bigwidth - $width);
- }
-
- if ($just == 'left')
- {
- $offset = 0;
- }
- }
-
- if ($type == "jpeg"){
- $this->addJpegFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
- }
- if ($type == "png"){
- $this->addPngFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
- }
-
- if ($border != '')
- {
- if (!(isset($border['color'])))
- {
- $border['color']['red'] = .5;
- $border['color']['blue'] = .5;
- $border['color']['green'] = .5;
- }
- if (!(isset($border['width']))) $border['width'] = 1;
- if (!(isset($border['cap']))) $border['cap'] = 'round';
- if (!(isset($border['join']))) $border['join'] = 'round';
- $this->setStrokeColor($border['color']['red'],$border['color']['green'],$border['color']['blue']);
- $this->setLineStyle($border['width'],$border['cap'],$border['join']);
- $this->rectangle($this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width,$height);
- }
-
- $this->y = $this->y - $pad - $height;
-
- if ($temp == true) unlink($image);
- }
- function loadTemplate($templateFile){
-
-
-
-
- if (!file_exists($templateFile)){
- return -1;
- }
- $code = implode('',file($templateFile));
- if (!strlen($code)){
- return;
- }
- $code = trim($code);
- if (substr($code,0,5)=='<?php'){
- $code = substr($code,5);
- }
- if (substr($code,-2)=='?>'){
- $code = substr($code,0,strlen($code)-2);
- }
- if (isset($this->ez['numTemplates'])){
- $newNum = $this->ez['numTemplates'];
- $this->ez['numTemplates']++;
- } else {
- $newNum=0;
- $this->ez['numTemplates']=1;
- $this->ez['templates']=array();
- }
- $this->ez['templates'][$newNum]['code']=$code;
- return $newNum;
- }
- function execTemplate($id,$data=array(),$options=array()){
-
- if (!isset($this->ez['templates'][$id])){
- return;
- }
- eval($this->ez['templates'][$id]['code']);
- }
- function ilink($info){
- $this->alink($info,1);
- }
- function alink($info,$internal=0){
-
- $lineFactor=0.05;
- switch($info['status']){
- case 'start':
- case 'sol':
-
-
- if (!isset($this->ez['links'])){
- $this->ez['links']=array();
- }
- $i = $info['nCallback'];
- $this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height'],'url'=>$info['p']);
- if ($internal==0){
- $this->saveState();
- $this->setColor(0,0,1);
- $this->setStrokeColor(0,0,1);
- $thick = $info['height']*$lineFactor;
- $this->setLineStyle($thick);
- }
- break;
- case 'end':
- case 'eol':
-
-
- $i = $info['nCallback'];
- $start = $this->ez['links'][$i];
-
- if ($internal){
- $this->addInternalLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);
- } else {
- $a = deg2rad((float)$start['angle']-90.0);
- $drop = $start['height']*$lineFactor*1.5;
- $dropx = cos($a)*$drop;
- $dropy = -sin($a)*$drop;
- $this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);
- $this->addLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);
- $this->restoreState();
- }
- break;
- }
- }
- function uline($info){
-
- $lineFactor=0.05;
- switch($info['status']){
- case 'start':
- case 'sol':
-
- if (!isset($this->ez['links'])){
- $this->ez['links']=array();
- }
- $i = $info['nCallback'];
- $this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height']);
- $this->saveState();
- $thick = $info['height']*$lineFactor;
- $this->setLineStyle($thick);
- break;
- case 'end':
- case 'eol':
-
-
- $i = $info['nCallback'];
- $start = $this->ez['links'][$i];
-
- $a = deg2rad((float)$start['angle']-90.0);
- $drop = $start['height']*$lineFactor*1.5;
- $dropx = cos($a)*$drop;
- $dropy = -sin($a)*$drop;
- $this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);
- $this->restoreState();
- break;
- }
- }
- }
- ?>
|