Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class ezpdf extends cpdf

Helix cpdf ezpdf
Hide Inherited MembersHelix Core
Description
No description.
 
Constants
No constants.
 
Properties
publicaddLooseObjects[ cpdf ]
publicarc4[ cpdf ]
publicarc4_objnum[ cpdf ]
publiccallback[ cpdf ]
publiccatalogId[ cpdf ]
publiccheckpoint[ cpdf ]
publiccurrentBaseFont[ cpdf ]
publiccurrentColour[ cpdf ]
publiccurrentContents[ cpdf ]
publiccurrentFont[ cpdf ]
publiccurrentFontNum[ cpdf ]
publiccurrentLineStyle[ cpdf ]
publiccurrentNode[ cpdf ]
publiccurrentPage[ cpdf ]
publiccurrentStrokeColour[ cpdf ]
publiccurrentTextState[ cpdf ]
publicdestinations[ cpdf ]
publicencrypted[ cpdf ]
publicencryptionKey[ cpdf ]
publicez[ ezpdf ]
publicezPageCount[ ezpdf ]
publicezPages[ ezpdf ]
publicfileIdentifier[ cpdf ]
publicfirstPageId[ cpdf ]
publicfontFamilies[ cpdf ]
publicfonts[ cpdf ]
publicinfoObject[ cpdf ]
publiclooseObjects[ cpdf ]
publicmessages[ cpdf ]
publicnCallback[ cpdf ]
publicnStack[ cpdf ]
publicnStateStack[ cpdf ]
publicnumFonts[ cpdf ]
publicnumImages[ cpdf ]
publicnumObj[ cpdf ]
publicnumPages[ cpdf ]
publicobjects[ cpdf ]
publicoptions[ cpdf ]
publicprocsetObjectId[ cpdf ]
publicstack[ cpdf ]
publicstateStack[ cpdf ]
publicwordSpaceAdjust[ cpdf ]
publicy[ ezpdf ]
 
Methods
publicARC4 ( text )[ cpdf ]
Parameters
requiredtext
Code
1122  function ARC4($text){
1123    $len=strlen($text);
1124    $a=0;
1125    $b=0;
1126    $c = $this->arc4;
1127    $out='';
1128    for ($i=0;$i<$len;$i++){
1129      $a = ($a+1)%256;
1130      $t= $c[$a];
1131      $b = ($b+ord($t))%256;
1132      $c[$a]=$c[$b];
1133      $c[$b]=$t;
1134      $k = ord($c[(ord($c[$a])+ord($c[$b]))%256]);
1135      $out.=chr(ord($text[$i]) ^ $k);
1136    }
1137 
1138    return $out;
1139  }
publicARC4_init ( key [""] )[ cpdf ]
Parameters
optionalkey [""]
Code
1096  function ARC4_init($key=''){
1097    $this->arc4 = '';
1098    // setup the control array
1099    if (strlen($key)==0){
1100      return;
1101    }
1102    $k = '';
1103    while(strlen($k)<256){
1104      $k.=$key;
1105    }
1106    $k=substr($k,0,256);
1107    for ($i=0;$i<256;$i++){
1108      $this->arc4 .= chr($i);
1109    }
1110    $j=0;
1111    for ($i=0;$i<256;$i++){
1112      $t = $this->arc4[$i];
1113      $j = ($j + ord($t) + ord($k[$i]))%256;
1114      $this->arc4[$i]=$this->arc4[$j];
1115      $this->arc4[$j]=$t;
1116    }
1117  }
publicPRVT_getBytes ( &data , pos , num )[ cpdf ]
Parameters
required&data
requiredpos
requirednum
Code
2616  function PRVT_getBytes(&$data,$pos,$num){
2617    // return the integer represented by $num bytes from $pos within $data
2618    $ret=0;
2619    for ($i=0;$i<$num;$i++){
2620      $ret=$ret*256;
2621      $ret+=ord($data[$pos+$i]);
2622    }
2623    return $ret;
2624  }
publicPRVTadjustWrapText ( text , actual , width , &x , &adjust , justification )[ cpdf ]
Parameters
requiredtext
requiredactual
requiredwidth
required&x
required&adjust
requiredjustification
Code
2294  function PRVTadjustWrapText($text,$actual,$width,&$x,&$adjust,$justification){
2295    switch ($justification){
2296      case 'left':
2297        return;
2298      case 'right':
2299        $x+=$width-$actual;
2300        break;
2301      case 'center':
2302      case 'centre':
2303        $x+=($width-$actual)/2;
2304        break;
2305      case 'full':
2306        // count the number of words
2307        $words = explode(' ',$text);
2308        $nspaces=count($words)-1;
2309        if ($nspaces>0){
2310          $adjust = ($width-$actual)/$nspaces;
2311        } else {
2312          $adjust=0;
2313        }
2314        break;
2315    }
2316  }
publicPRVTcheckTextDirective ( &text , i , &f )[ cpdf ]
Parameters
required&text
requiredi
required&f
Code
1987  function PRVTcheckTextDirective(&$text,$i,&$f){
1988    $x=0;
1989    $y=0;
1990    return $this->PRVTcheckTextDirective1($text,$i,$f,0,$x,$y);
1991  }
publicPRVTcheckTextDirective1 ( &text , i , &f , final , &x , &y , size [0] , angle [0] , wordSpaceAdjust [0] )[ cpdf ]
Parameters
required&text
requiredi
required&f
requiredfinal
required&x
required&y
optionalsize [0]
optionalangle [0]
optionalwordSpaceAdjust [0]
Code
2002  function PRVTcheckTextDirective1(&$text,$i,&$f,$final,&$x,&$y,$size=0,$angle=0,$wordSpaceAdjust=0){
2003    $directive = 0;
2004    $j=$i;
2005    if ($text[$j]=='<'){
2006      $j++;
2007      switch($text[$j]){
2008        case '/':
2009          $j++;
2010          if (strlen($text) <= $j){
2011            return $directive;
2012          }
2013          switch($text[$j]){
2014            case 'b':
2015            case 'i':
2016              $j++;
2017              if ($text[$j]=='>'){
2018                $p = strrpos($this->currentTextState,$text[$j-1]);
2019                if ($p !== false){
2020                  // then there is one to remove
2021                  $this->currentTextState = substr($this->currentTextState,0,$p).substr($this->currentTextState,$p+1);
2022                }
2023                $directive=$j-$i+1;
2024              }
2025              break;
2026            case 'c':
2027              // this this might be a callback function
2028              $j++;
2029              $k = strpos($text,'>',$j);
2030              if ($k!==false && $text[$j]==':'){
2031                // then this will be treated as a callback directive
2032                $directive = $k-$i+1;
2033                $f=0;
2034                // split the remainder on colons to get the function name and the paramater
2035                $tmp = substr($text,$j+1,$k-$j-1);
2036                $b1 = strpos($tmp,':');
2037                if ($b1!==false){
2038                  $func = substr($tmp,0,$b1);
2039                  $parm = substr($tmp,$b1+1);
2040                } else {
2041                  $func=$tmp;
2042                  $parm='';
2043                }
2044                if (!isset($func) || !strlen(trim($func))){
2045                  $directive=0;
2046                } else {
2047                  // only call the function if this is the final call
2048                  if ($final){
2049                    // need to assess the text position, calculate the text width to this point
2050                    // can use getTextWidth to find the text width I think
2051                    $tmp = $this->PRVTgetTextPosition($x,$y,$angle,$size,$wordSpaceAdjust,substr($text,0,$i));
2052                    $info = array('x'=>$tmp[0],'y'=>$tmp[1],'angle'=>$angle,'status'=>'end','p'=>$parm,'nCallback'=>$this->nCallback);
2053                    $x=$tmp[0];
2054                    $y=$tmp[1];
2055                    $ret = $this->$func($info);
2056                    if (is_array($ret)){
2057                      // then the return from the callback function could set the position, to start with, later will do font colour, and font
2058                      foreach($ret as $rk=>$rv){
2059                        switch($rk){
2060                          case 'x':
2061                          case 'y':
2062                            $$rk=$rv;
2063                            break;
2064                        }
2065                      }
2066                    }
2067                    // also remove from to the stack
2068                    // for simplicity, just take from the end, fix this another day
2069                    $this->nCallback--;
2070                    if ($this->nCallback<0){
2071                      $this->nCallBack=0;
2072                    }
2073                  }
2074                }
2075              }
2076              break;
2077          }
2078          break;
2079        case 'b':
2080        case 'i':
2081          $j++;
2082          if ($text[$j]=='>'){
2083            $this->currentTextState.=$text[$j-1];
2084            $directive=$j-$i+1;
2085          }
2086          break;
2087        case 'C':
2088          $noClose=1;
2089        case 'c':
2090          // this this might be a callback function
2091          $j++;
2092          $k = strpos($text,'>',$j);
2093          if ($k!==false && $text[$j]==':'){
2094            // then this will be treated as a callback directive
2095            $directive = $k-$i+1;
2096            $f=0;
2097            // split the remainder on colons to get the function name and the paramater
2098  //          $bits = explode(':',substr($text,$j+1,$k-$j-1));
2099            $tmp = substr($text,$j+1,$k-$j-1);
2100            $b1 = strpos($tmp,':');
2101            if ($b1!==false){
2102              $func = substr($tmp,0,$b1);
2103              $parm = substr($tmp,$b1+1);
2104            } else {
2105              $func=$tmp;
2106              $parm='';
2107            }
2108            if (!isset($func) || !strlen(trim($func))){
2109              $directive=0;
2110            } else {
2111              // only call the function if this is the final call, ie, the one actually doing printing, not measurement
2112              if ($final){
2113                // need to assess the text position, calculate the text width to this point
2114                // can use getTextWidth to find the text width I think
2115                // also add the text height and decender
2116                $tmp = $this->PRVTgetTextPosition($x,$y,$angle,$size,$wordSpaceAdjust,substr($text,0,$i));
2117                $info = array('x'=>$tmp[0],'y'=>$tmp[1],'angle'=>$angle,'status'=>'start','p'=>$parm,'f'=>$func,'height'=>$this->getFontHeight($size),'decender'=>$this->getFontDecender($size));
2118                $x=$tmp[0];
2119                $y=$tmp[1];
2120                if (!isset($noClose) || !$noClose){
2121                  // only add to the stack if this is a small 'c', therefore is a start-stop pair
2122                  $this->nCallback++;
2123                  $info['nCallback']=$this->nCallback;
2124                  $this->callback[$this->nCallback]=$info;
2125                }
2126                $ret = $this->$func($info);
2127                if (is_array($ret)){
2128                  // then the return from the callback function could set the position, to start with, later will do font colour, and font
2129                  foreach($ret as $rk=>$rv){
2130                    switch($rk){
2131                      case 'x':
2132                      case 'y':
2133                        $$rk=$rv;
2134                        break;
2135                    }
2136                  }
2137                }
2138              }
2139            }
2140          }
2141          break;
2142      }
2143    }
2144    return $directive;
2145  }
publicPRVTgetTextPosition ( x , y , angle , size , wa , text )[ cpdf ]
Parameters
requiredx
requiredy
requiredangle
requiredsize
requiredwa
requiredtext
Code
1971  function PRVTgetTextPosition($x,$y,$angle,$size,$wa,$text){
1972    // given this information return an array containing x and y for the end position as elements 0 and 1
1973    $w = $this->getTextWidth($size,$text);
1974    // need to adjust for the number of spaces in this text
1975    $words = explode(' ',$text);
1976    $nspaces=count($words)-1;
1977    $w += $wa*$nspaces;
1978    $a = deg2rad((float)$angle);
1979    return array(cos($a)*$w+$x,-sin($a)*$w+$y);
1980  }
publicaddContent ( content )[ cpdf ]
Parameters
requiredcontent
Code
1632  function addContent($content){
1633    $this->objects[$this->currentContents]['c'].=$content;
1634  }
publicaddDestination ( label , style , a [0] , b [0] , c [0] )[ cpdf ]
Parameters
requiredlabel
requiredstyle
optionala [0]
optionalb [0]
optionalc [0]
Code
2962  function addDestination($label,$style,$a=0,$b=0,$c=0){
2963    // associates the given label with the destination, it is done this way so that a destination can be specified after
2964    // it has been linked to
2965    // styles are the same as the 'openHere' function
2966    $this->numObj++;
2967    $this->o_destination($this->numObj,'new',array('page'=>$this->currentPage,'type'=>$style,'p1'=>$a,'p2'=>$b,'p3'=>$c));
2968    $id = $this->numObj;
2969    // store the label->idf relationship, note that this means that labels can be used only once
2970    $this->destinations["$label"]=$id;
2971  }
publicaddImage ( &img , x , y , w [0] , h [0] , quality [75] )[ cpdf ]
Parameters
required&img
requiredx
requiredy
optionalw [0]
optionalh [0]
optionalquality [75]
Code
2863  function addImage(&$img,$x,$y,$w=0,$h=0,$quality=75){
2864    // add a new image into the current location, as an external object
2865    // add the image at $x,$y, and with width and height as defined by $w & $h
2866 
2867    // note that this will only work with full colour images and makes them jpg images for display
2868    // later versions could present lossless image formats if there is interest.
2869 
2870    // there seems to be some problem here in that images that have quality set above 75 do not appear
2871    // not too sure why this is, but in the meantime I have restricted this to 75.
2872    if ($quality>75){
2873      $quality=75;
2874    }
2875 
2876    // if the width or height are set to zero, then set the other one based on keeping the image
2877    // height/width ratio the same, if they are both zero, then give up :)
2878    $imageWidth=imagesx($img);
2879    $imageHeight=imagesy($img);
2880 
2881    if ($w<=0 && $h<=0){
2882      return;
2883    }
2884    if ($w==0){
2885      $w=$h/$imageHeight*$imageWidth;
2886    }
2887    if ($h==0){
2888      $h=$w*$imageHeight/$imageWidth;
2889    }
2890 
2891    // gotta get the data out of the img..
2892 
2893    // so I write to a temp file, and then read it back.. soo ugly, my apologies.
2894    $tmpDir='/tmp';
2895    $tmpName=tempnam($tmpDir,'img');
2896    imagejpeg($img,$tmpName,$quality);
2897    $fp=fopen($tmpName,'rb');
2898 
2899    $tmp = get_magic_quotes_runtime();
2900    set_magic_quotes_runtime(0);
2901    $fp = @fopen($tmpName,'rb');
2902    if ($fp){
2903      $data='';
2904      while(!feof($fp)){
2905        $data .= fread($fp,1024);
2906      }
2907      fclose($fp);
2908    } else {
2909      $error = 1;
2910      $errormsg = 'trouble opening file';
2911    }
2912  //  $data = fread($fp,filesize($tmpName));
2913    set_magic_quotes_runtime($tmp);
2914  //  fclose($fp);
2915    unlink($tmpName);
2916    $this->addJpegImage_common($data,$x,$y,$w,$h,$imageWidth,$imageHeight);
2917  }
publicaddInfo ( label , value [0] )[ cpdf ]
Parameters
requiredlabel
optionalvalue [0]
Code
2583  function addInfo($label,$value=0){
2584    // this will only work if the label is one of the valid ones.
2585    // modify this so that arrays can be passed as well.
2586    // if $label is an array then assume that it is key=>value pairs
2587    // else assume that they are both scalar, anything else will probably error
2588    if (is_array($label)){
2589      foreach ($label as $l=>$v){
2590        $this->o_info($this->infoObject,$l,$v);
2591      }
2592    } else {
2593      $this->o_info($this->infoObject,$label,$value);
2594    }
2595  }
publicaddInternalLink ( label , x0 , y0 , x1 , y1 )[ cpdf ]
publicaddJpegFromFile ( img , x , y , w [0] , h [0] )[ cpdf ]
Parameters
requiredimg
requiredx
requiredy
optionalw [0]
optionalh [0]
Code
2818  function addJpegFromFile($img,$x,$y,$w=0,$h=0){
2819    // attempt to add a jpeg image straight from a file, using no GD commands
2820    // note that this function is unable to operate on a remote file.
2821 
2822    if (!file_exists($img)){
2823      return;
2824    }
2825 
2826    $tmp=getimagesize($img);
2827    $imageWidth=$tmp[0];
2828    $imageHeight=$tmp[1];
2829 
2830    if (isset($tmp['channels'])){
2831      $channels = $tmp['channels'];
2832    } else {
2833      $channels = 3;
2834    }
2835 
2836    if ($w<=0 && $h<=0){
2837      $w=$imageWidth;
2838    }
2839    if ($w==0){
2840      $w=$h/$imageHeight*$imageWidth;
2841    }
2842    if ($h==0){
2843      $h=$w*$imageHeight/$imageWidth;
2844    }
2845 
2846    $fp=fopen($img,'rb');
2847 
2848    $tmp = get_magic_quotes_runtime();
2849    set_magic_quotes_runtime(0);
2850    $data = fread($fp,filesize($img));
2851    set_magic_quotes_runtime($tmp);
2852 
2853    fclose($fp);
2854 
2855    $this->addJpegImage_common($data,$x,$y,$w,$h,$imageWidth,$imageHeight,$channels);
2856  }
publicaddJpegImage_common ( &data , x , y , w , h , imageWidth , imageHeight , channels [3] )[ cpdf ]
Parameters
required&data
requiredx
requiredy
requiredw
requiredh
requiredimageWidth
requiredimageHeight
optionalchannels [3]
Code
2924  function addJpegImage_common(&$data,$x,$y,$w=0,$h=0,$imageWidth,$imageHeight,$channels=3){
2925    // note that this function is not to be called externally
2926    // it is just the common code between the GD and the file options
2927    $this->numImages++;
2928    $im=$this->numImages;
2929    $label='I'.$im;
2930    $this->numObj++;
2931    $this->o_image($this->numObj,'new',array('label'=>$label,'data'=>$data,'iw'=>$imageWidth,'ih'=>$imageHeight,'channels'=>$channels));
2932 
2933    $this->objects[$this->currentContents]['c'].="\nq";
2934    $this->objects[$this->currentContents]['c'].="\n".sprintf('%.3f',$w)." 0 0 ".sprintf('%.3f',$h)." ".sprintf('%.3f',$x)." ".sprintf('%.3f',$y)." cm";
2935    $this->objects[$this->currentContents]['c'].="\n/".$label.' Do';
2936    $this->objects[$this->currentContents]['c'].="\nQ";
2937  }
publicaddLink ( url , x0 , y0 , x1 , y1 )[ cpdf ]
publicaddMessage ( message )[ cpdf ]
Parameters
requiredmessage
Code
3015  function addMessage($message){
3016    $this->messages.=$message."\n";
3017  }
publicaddObject ( id , options ["add"] )[ cpdf ]
Parameters
requiredid
optionaloptions ["add"]
Code
2537  function addObject($id,$options='add'){
2538    // add the specified object to the page
2539    if (isset($this->looseObjects[$id]) && $this->currentContents!=$id){
2540      // then it is a valid object, and it is not being added to itself
2541      switch($options){
2542        case 'all':
2543          // then this object is to be added to this page (done in the next block) and
2544          // all future new pages.
2545          $this->addLooseObjects[$id]='all';
2546        case 'add':
2547          if (isset($this->objects[$this->currentContents]['onPage'])){
2548            // then the destination contents is the primary for the page
2549            // (though this object is actually added to that page)
2550            $this->o_page($this->objects[$this->currentContents]['onPage'],'content',$id);
2551          }
2552          break;
2553        case 'even':
2554          $this->addLooseObjects[$id]='even';
2555          $pageObjectId=$this->objects[$this->currentContents]['onPage'];
2556          if ($this->objects[$pageObjectId]['info']['pageNum']%2==0){
2557            $this->addObject($id); // hacky huh :)
2558          }
2559          break;
2560        case 'odd':
2561          $this->addLooseObjects[$id]='odd';
2562          $pageObjectId=$this->objects[$this->currentContents]['onPage'];
2563          if ($this->objects[$pageObjectId]['info']['pageNum']%2==1){
2564            $this->addObject($id); // hacky huh :)
2565          }
2566          break;
2567        case 'next':
2568          $this->addLooseObjects[$id]='all';
2569          break;
2570        case 'nexteven':
2571          $this->addLooseObjects[$id]='even';
2572          break;
2573        case 'nextodd':
2574          $this->addLooseObjects[$id]='odd';
2575          break;
2576      }
2577    }
2578  }
publicaddPngFromFile ( file , x , y , w [0] , h [0] )[ cpdf ]
Parameters
requiredfile
requiredx
requiredy
optionalw [0]
optionalh [0]
Code
2630  function addPngFromFile($file,$x,$y,$w=0,$h=0){
2631    // read in a png file, interpret it, then add to the system
2632    $error=0;
2633    $tmp = get_magic_quotes_runtime();
2634    set_magic_quotes_runtime(0);
2635    $fp = @fopen($file,'rb');
2636    if ($fp){
2637      $data='';
2638      while(!feof($fp)){
2639        $data .= fread($fp,1024);
2640      }
2641      fclose($fp);
2642    } else {
2643      $error = 1;
2644      $errormsg = 'trouble opening file: '.$file;
2645    }
2646    set_magic_quotes_runtime($tmp);
2647 
2648    if (!$error){
2649      $header = chr(137).chr(80).chr(78).chr(71).chr(13).chr(10).chr(26).chr(10);
2650      if (substr($data,0,8)!=$header){
2651        $error=1;
2652        $errormsg = 'this file does not have a valid header';
2653      }
2654    }
2655 
2656    if (!$error){
2657      // set pointer
2658      $p = 8;
2659      $len = strlen($data);
2660      // cycle through the file, identifying chunks
2661      $haveHeader=0;
2662      $info=array();
2663      $idata='';
2664      $pdata='';
2665      while ($p<$len){
2666        $chunkLen = $this->PRVT_getBytes($data,$p,4);
2667        $chunkType = substr($data,$p+4,4);
2668  //      echo $chunkType.' - '.$chunkLen.'<br>';
2669 
2670        switch($chunkType){
2671          case 'IHDR':
2672            // this is where all the file information comes from
2673            $info['width']=$this->PRVT_getBytes($data,$p+8,4);
2674            $info['height']=$this->PRVT_getBytes($data,$p+12,4);
2675            $info['bitDepth']=ord($data[$p+16]);
2676            $info['colorType']=ord($data[$p+17]);
2677            $info['compressionMethod']=ord($data[$p+18]);
2678            $info['filterMethod']=ord($data[$p+19]);
2679            $info['interlaceMethod']=ord($data[$p+20]);
2680  //print_r($info);
2681            $haveHeader=1;
2682            if ($info['compressionMethod']!=0){
2683              $error=1;
2684              $errormsg = 'unsupported compression method';
2685            }
2686            if ($info['filterMethod']!=0){
2687              $error=1;
2688              $errormsg = 'unsupported filter method';
2689            }
2690            break;
2691          case 'PLTE':
2692            $pdata.=substr($data,$p+8,$chunkLen);
2693            break;
2694          case 'IDAT':
2695            $idata.=substr($data,$p+8,$chunkLen);
2696            break;
2697          case 'tRNS':
2698            //this chunk can only occur once and it must occur after the PLTE chunk and before IDAT chunk
2699            //print "tRNS found, color type = ".$info['colorType']."<BR>";
2700            $transparency = array();
2701            if ($info['colorType'] == 3) { // indexed color, rbg
2702            /* corresponding to entries in the plte chunk
2703            Alpha for palette index 0: 1 byte
2704            Alpha for palette index 1: 1 byte
2705            ...etc...
2706            */
2707              // there will be one entry for each palette entry. up until the last non-opaque entry.
2708              // set up an array, stretching over all palette entries which will be o (opaque) or 1 (transparent)
2709              $transparency['type']='indexed';
2710              $numPalette = strlen($pdata)/3;
2711              $trans=0;
2712              for ($i=$chunkLen;$i>=0;$i--){
2713                if (ord($data[$p+8+$i])==0){
2714                  $trans=$i;
2715                }
2716              }
2717              $transparency['data'] = $trans;
2718 
2719            } elseif($info['colorType'] == 0) { // grayscale
2720            /* corresponding to entries in the plte chunk
2721            Gray: 2 bytes, range 0 .. (2^bitdepth)-1
2722            */
2723  //            $transparency['grayscale']=$this->PRVT_getBytes($data,$p+8,2); // g = grayscale
2724              $transparency['type']='indexed';
2725              $transparency['data'] = ord($data[$p+8+1]);
2726 
2727            } elseif($info['colorType'] == 2) { // truecolor
2728            /* corresponding to entries in the plte chunk
2729            Red: 2 bytes, range 0 .. (2^bitdepth)-1
2730            Green: 2 bytes, range 0 .. (2^bitdepth)-1
2731            Blue: 2 bytes, range 0 .. (2^bitdepth)-1
2732            */
2733              $transparency['r']=$this->PRVT_getBytes($data,$p+8,2); // r from truecolor
2734              $transparency['g']=$this->PRVT_getBytes($data,$p+10,2); // g from truecolor
2735              $transparency['b']=$this->PRVT_getBytes($data,$p+12,2); // b from truecolor
2736 
2737            } else {
2738            //unsupported transparency type
2739            }
2740            // KS End new code
2741            break;
2742          default:
2743            break;
2744        }
2745 
2746        $p += $chunkLen+12;
2747      }
2748 
2749      if(!$haveHeader){
2750        $error = 1;
2751        $errormsg = 'information header is missing';
2752      }
2753      if (isset($info['interlaceMethod']) && $info['interlaceMethod']){
2754        $error = 1;
2755        $errormsg = 'There appears to be no support for interlaced images in pdf.';
2756      }
2757    }
2758 
2759    if (!$error && $info['bitDepth'] > 8){
2760      $error = 1;
2761      $errormsg = 'only bit depth of 8 or less is supported';
2762    }
2763 
2764    if (!$error){
2765      if ($info['colorType']!=2 && $info['colorType']!=0 && $info['colorType']!=3){
2766        $error = 1;
2767        $errormsg = 'transparancey alpha channel not supported, transparency only supported for palette images.';
2768      } else {
2769        switch ($info['colorType']){
2770          case 3:
2771            $color = 'DeviceRGB';
2772            $ncolor=1;
2773            break;
2774          case 2:
2775            $color = 'DeviceRGB';
2776            $ncolor=3;
2777            break;
2778          case 0:
2779            $color = 'DeviceGray';
2780            $ncolor=1;
2781            break;
2782        }
2783      }
2784    }
2785    if ($error){
2786      $this->addMessage('PNG error - ('.$file.') '.$errormsg);
2787      return;
2788    }
2789    if ($w==0){
2790      $w=$h/$info['height']*$info['width'];
2791    }
2792    if ($h==0){
2793      $h=$w*$info['height']/$info['width'];
2794    }
2795  //print_r($info);
2796    // so this image is ok... add it in.
2797    $this->numImages++;
2798    $im=$this->numImages;
2799    $label='I'.$im;
2800    $this->numObj++;
2801  //  $this->o_image($this->numObj,'new',array('label'=>$label,'data'=>$idata,'iw'=>$w,'ih'=>$h,'type'=>'png','ic'=>$info['width']));
2802    $options = array('label'=>$label,'data'=>$idata,'bitsPerComponent'=>$info['bitDepth'],'pdata'=>$pdata
2803                                        ,'iw'=>$info['width'],'ih'=>$info['height'],'type'=>'png','color'=>$color,'ncolor'=>$ncolor);
2804    if (isset($transparency)){
2805      $options['transparency']=$transparency;
2806    }
2807    $this->o_image($this->numObj,'new',$options);
2808 
2809    $this->objects[$this->currentContents]['c'].="\nq";
2810    $this->objects[$this->currentContents]['c'].="\n".sprintf('%.3f',$w)." 0 0 ".sprintf('%.3f',$h)." ".sprintf('%.3f',$x)." ".sprintf('%.3f',$y)." cm";
2811    $this->objects[$this->currentContents]['c'].="\n/".$label.' Do';
2812    $this->objects[$this->currentContents]['c'].="\nQ";
2813  }
publicaddText ( x , y , size , text , angle [0] , wordSpaceAdjust [0] )[ cpdf ]
Parameters
requiredx
requiredy
requiredsize
requiredtext
optionalangle [0]
optionalwordSpaceAdjust [0]
Code
2150  function addText($x,$y,$size,$text,$angle=0,$wordSpaceAdjust=0){
2151    if (!$this->numFonts){$this->selectFont(SITES  . 'helix/resources/fonts/Helvetica');}
2152 
2153    // if there are any open callbacks, then they should be called, to show the start of the line
2154    if ($this->nCallback>0){
2155      for ($i=$this->nCallback;$i>0;$i--){
2156        // call each function
2157        $info = array('x'=>$x,'y'=>$y,'angle'=>$angle,'status'=>'sol','p'=>$this->callback[$i]['p'],'nCallback'=>$this->callback[$i]['nCallback'],'height'=>$this->callback[$i]['height'],'decender'=>$this->callback[$i]['decender']);
2158        $func = $this->callback[$i]['f'];
2159        $this->$func($info);
2160      }
2161    }
2162    if ($angle==0){
2163      $this->objects[$this->currentContents]['c'].="\n".'BT '.sprintf('%.3f',$x).' '.sprintf('%.3f',$y).' Td';
2164    } else {
2165      $a = deg2rad((float)$angle);
2166      $tmp = "\n".'BT ';
2167      $tmp .= sprintf('%.3f',cos($a)).' '.sprintf('%.3f',(-1.0*sin($a))).' '.sprintf('%.3f',sin($a)).' '.sprintf('%.3f',cos($a)).' ';
2168      $tmp .= sprintf('%.3f',$x).' '.sprintf('%.3f',$y).' Tm';
2169      $this->objects[$this->currentContents]['c'] .= $tmp;
2170    }
2171    if ($wordSpaceAdjust!=0 || $wordSpaceAdjust != $this->wordSpaceAdjust){
2172      $this->wordSpaceAdjust=$wordSpaceAdjust;
2173      $this->objects[$this->currentContents]['c'].=' '.sprintf('%.3f',$wordSpaceAdjust).' Tw';
2174    }
2175    $len=strlen($text);
2176    $start=0;
2177    for ($i=0;$i<$len;$i++){
2178      $f=1;
2179      $directive = $this->PRVTcheckTextDirective($text,$i,$f);
2180      if ($directive){
2181        // then we should write what we need to
2182        if ($i>$start){
2183          $part = substr($text,$start,$i-$start);
2184          $this->objects[$this->currentContents]['c'].=' /F'.$this->currentFontNum.' '.sprintf('%.1f',$size).' Tf ';
2185          $this->objects[$this->currentContents]['c'].=' ('.$this->filterText($part).') Tj';
2186        }
2187        if ($f){
2188          // then there was nothing drastic done here, restore the contents
2189          $this->setCurrentFont();
2190        } else {
2191          $this->objects[$this->currentContents]['c'] .= ' ET';
2192          $f=1;
2193          $xp=$x;
2194          $yp=$y;
2195          $directive = $this->PRVTcheckTextDirective1($text,$i,$f,1,$xp,$yp,$size,$angle,$wordSpaceAdjust);
2196 
2197          // restart the text object
2198            if ($angle==0){
2199              $this->objects[$this->currentContents]['c'].="\n".'BT '.sprintf('%.3f',$xp).' '.sprintf('%.3f',$yp).' Td';
2200            } else {
2201              $a = deg2rad((float)$angle);
2202              $tmp = "\n".'BT ';
2203              $tmp .= sprintf('%.3f',cos($a)).' '.sprintf('%.3f',(-1.0*sin($a))).' '.sprintf('%.3f',sin($a)).' '.sprintf('%.3f',cos($a)).' ';
2204              $tmp .= sprintf('%.3f',$xp).' '.sprintf('%.3f',$yp).' Tm';
2205              $this->objects[$this->currentContents]['c'] .= $tmp;
2206            }
2207            if ($wordSpaceAdjust!=0 || $wordSpaceAdjust != $this->wordSpaceAdjust){
2208              $this->wordSpaceAdjust=$wordSpaceAdjust;
2209              $this->objects[$this->currentContents]['c'].=' '.sprintf('%.3f',$wordSpaceAdjust).' Tw';
2210            }
2211        }
2212        // and move the writing point to the next piece of text
2213        $i=$i+$directive-1;
2214        $start=$i+1;
2215      }
2216 
2217    }
2218    if ($start<$len){
2219      $part = substr($text,$start);
2220      $this->objects[$this->currentContents]['c'].=' /F'.$this->currentFontNum.' '.sprintf('%.1f',$size).' Tf ';
2221      $this->objects[$this->currentContents]['c'].=' ('.$this->filterText($part).') Tj';
2222    }
2223    $this->objects[$this->currentContents]['c'].=' ET';
2224 
2225    // if there are any open callbacks, then they should be called, to show the end of the line
2226    if ($this->nCallback>0){
2227      for ($i=$this->nCallback;$i>0;$i--){
2228        // call each function
2229        $tmp = $this->PRVTgetTextPosition($x,$y,$angle,$size,$wordSpaceAdjust,$text);
2230        $info = array('x'=>$tmp[0],'y'=>$tmp[1],'angle'=>$angle,'status'=>'eol','p'=>$this->callback[$i]['p'],'nCallback'=>$this->callback[$i]['nCallback'],'height'=>$this->callback[$i]['height'],'decender'=>$this->callback[$i]['decender']);
2231        $func = $this->callback[$i]['f'];
2232        $this->$func($info);
2233      }
2234    }
2235 
2236  }
publicaddTextWrap ( x , y , width , size , text , justification ["left"] , angle [0] , test [0] )[ cpdf ]
Parameters
requiredx
requiredy
requiredwidth
requiredsize
requiredtext
optionaljustification ["left"]
optionalangle [0]
optionaltest [0]
Code
2324  function addTextWrap($x,$y,$width,$size,$text,$justification='left',$angle=0,$test=0){
2325    // this will display the text, and if it goes beyond the width $width, will backtrack to the
2326    // previous space or hyphen, and return the remainder of the text.
2327 
2328    // $justification can be set to 'left','right','center','centre','full'
2329 
2330    // need to store the initial text state, as this will change during the width calculation
2331    // but will need to be re-set before printing, so that the chars work out right
2332    $store_currentTextState = $this->currentTextState;
2333 
2334    if (!$this->numFonts){$this->selectFont(SITES . 'helix/resources/fonts/Helvetica');}
2335    if ($width<=0){
2336      // error, pretend it printed ok, otherwise risking a loop
2337      return '';
2338    }
2339    $w=0;
2340    $break=0;
2341    $breakWidth=0;
2342    $len=strlen($text);
2343    $cf = $this->currentFont;
2344    $tw = $width/$size*1000;
2345    for ($i=0;$i<$len;$i++){
2346      $f=1;
2347      $directive = $this->PRVTcheckTextDirective($text,$i,$f);
2348      if ($directive){
2349        if ($f){
2350          $this->setCurrentFont();
2351          $cf = $this->currentFont;
2352        }
2353        $i=$i+$directive-1;
2354      } else {
2355        $cOrd = ord($text[$i]);
2356        if (isset($this->fonts[$cf]['differences'][$cOrd])){
2357          // then this character is being replaced by another
2358          $cOrd2 = $this->fonts[$cf]['differences'][$cOrd];
2359        } else {
2360          $cOrd2 = $cOrd;
2361        }
2362 
2363        if (isset($this->fonts[$cf]['C'][$cOrd2]['WX'])){
2364          $w+=$this->fonts[$cf]['C'][$cOrd2]['WX'];
2365        }
2366        if ($w>$tw){
2367          // then we need to truncate this line
2368          if ($break>0){
2369            // then we have somewhere that we can split :)
2370            if ($text[$break]==' '){
2371              $tmp = substr($text,0,$break);
2372            } else {
2373              $tmp = substr($text,0,$break+1);
2374            }
2375            $adjust=0;
2376            $this->PRVTadjustWrapText($tmp,$breakWidth,$width,$x,$adjust,$justification);
2377 
2378            // reset the text state
2379            $this->currentTextState = $store_currentTextState;
2380            $this->setCurrentFont();
2381            if (!$test){
2382              $this->addText($x,$y,$size,$tmp,$angle,$adjust);
2383            }
2384            return substr($text,$break+1);
2385          } else {
2386            // just split before the current character
2387            $tmp = substr($text,0,$i);
2388            $adjust=0;
2389            $ctmp=ord($text[$i]);
2390            if (isset($this->fonts[$cf]['differences'][$ctmp])){
2391              $ctmp=$this->fonts[$cf]['differences'][$ctmp];
2392            }
2393            $tmpw=($w-$this->fonts[$cf]['C'][$ctmp]['WX'])*$size/1000;
2394            $this->PRVTadjustWrapText($tmp,$tmpw,$width,$x,$adjust,$justification);
2395            // reset the text state
2396            $this->currentTextState = $store_currentTextState;
2397            $this->setCurrentFont();
2398            if (!$test){
2399              $this->addText($x,$y,$size,$tmp,$angle,$adjust);
2400            }
2401            return substr($text,$i);
2402          }
2403        }
2404        if ($text[$i]=='-'){
2405          $break=$i;
2406          $breakWidth = $w*$size/1000;
2407        }
2408        if ($text[$i]==' '){
2409          $break=$i;
2410          $ctmp=ord($text[$i]);
2411          if (isset($this->fonts[$cf]['differences'][$ctmp])){
2412            $ctmp=$this->fonts[$cf]['differences'][$ctmp];
2413          }
2414          $breakWidth = ($w-$this->fonts[$cf]['C'][$ctmp]['WX'])*$size/1000;
2415        }
2416      }
2417    }
2418    // then there was no need to break this line
2419    if ($justification=='full'){
2420      $justification='left';
2421    }
2422    $adjust=0;
2423    $tmpw=$w*$size/1000;
2424    $this->PRVTadjustWrapText($text,$tmpw,$width,$x,$adjust,$justification);
2425    // reset the text state
2426    $this->currentTextState = $store_currentTextState;
2427    $this->setCurrentFont();
2428    if (!$test){
2429      $this->addText($x,$y,$size,$text,$angle,$adjust,$angle);
2430    }
2431    return '';
2432  }
publicalink ( info , internal [0] )[ ezpdf ]
publiccheckAllHere ( )[ cpdf ]
Parameters
No parameters for this method
Code
1198  function checkAllHere(){
1199  }
publiccloseObject ( )[ cpdf ]
Parameters
No parameters for this method
Code
2511  function closeObject(){
2512    // close the object, as long as there was one open in the first place, which will be indicated by
2513    // an objectId on the stack.
2514    if ($this->nStack>0){
2515      $this->currentContents=$this->stack[$this->nStack]['c'];
2516      $this->currentPage=$this->stack[$this->nStack]['p'];
2517      $this->nStack--;
2518      // easier to probably not worry about removing the old entries, they will be overwritten
2519      // if there are new ones.
2520    }
2521  }
public__construct ( paper ["LETTER"] , orientation ["portrait"] )[ ezpdf ]
Parameters
optionalpaper ["LETTER"]
optionalorientation ["portrait"]
Code
025  public function __construct($paper='LETTER',$orientation='portrait'){
026  // Assuming that people don't want to specify the paper size using the absolute coordinates
027  // allow a couple of options:
028  // orientation can be 'portrait' or 'landscape'
029  // or, to actually set the coordinates, then pass an array in as the first parameter.
030  // the defaults are as shown.
031  //
032  // -------------------------
033  // 2002-07-24 - Nicola Asuni (info@tecnick.com):
034  // Added new page formats (45 standard ISO paper formats and 4 american common formats)
035  // paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm
036  //
037  // Now you may also pass a 2 values array containing the page width and height in centimeters
038  // -------------------------
039 
040  if (!is_array($paper)){
041      switch (strtoupper($paper)){
042          case '4A0': {$size = array(0,0,4767.87,6740.79); break;}
043          case '2A0': {$size = array(0,0,3370.39,4767.87); break;}
044          case 'A0': {$size = array(0,0,2383.94,3370.39); break;}
045          case 'A1': {$size = array(0,0,1683.78,2383.94); break;}
046          case 'A2': {$size = array(0,0,1190.55,1683.78); break;}
047          case 'A3': {$size = array(0,0,841.89,1190.55); break;}
048          case 'A4': {$size = array(0,0,595.28,841.89); break;}
049          case 'A5': {$size = array(0,0,419.53,595.28); break;}
050          case 'A6': {$size = array(0,0,297.64,419.53); break;}
051          case 'A7': {$size = array(0,0,209.76,297.64); break;}
052          case 'A8': {$size = array(0,0,147.40,209.76); break;}
053          case 'A9': {$size = array(0,0,104.88,147.40); break;}
054          case 'A10': {$size = array(0,0,73.70,104.88); break;}
055          case 'B0': {$size = array(0,0,2834.65,4008.19); break;}
056          case 'B1': {$size = array(0,0,2004.09,2834.65); break;}
057          case 'B2': {$size = array(0,0,1417.32,2004.09); break;}
058          case 'B3': {$size = array(0,0,1000.63,1417.32); break;}
059          case 'B4': {$size = array(0,0,708.66,1000.63); break;}
060          case 'B5': {$size = array(0,0,498.90,708.66); break;}
061          case 'B6': {$size = array(0,0,354.33,498.90); break;}
062          case 'B7': {$size = array(0,0,249.45,354.33); break;}
063          case 'B8': {$size = array(0,0,175.75,249.45); break;}
064          case 'B9': {$size = array(0,0,124.72,175.75); break;}
065          case 'B10': {$size = array(0,0,87.87,124.72); break;}
066          case 'C0': {$size = array(0,0,2599.37,3676.54); break;}
067          case 'C1': {$size = array(0,0,1836.85,2599.37); break;}
068          case 'C2': {$size = array(0,0,1298.27,1836.85); break;}
069          case 'C3': {$size = array(0,0,918.43,1298.27); break;}
070          case 'C4': {$size = array(0,0,649.13,918.43); break;}
071          case 'C5': {$size = array(0,0,459.21,649.13); break;}
072          case 'C6': {$size = array(0,0,323.15,459.21); break;}
073          case 'C7': {$size = array(0,0,229.61,323.15); break;}
074          case 'C8': {$size = array(0,0,161.57,229.61); break;}
075          case 'C9': {$size = array(0,0,113.39,161.57); break;}
076          case 'C10': {$size = array(0,0,79.37,113.39); break;}
077          case 'RA0': {$size = array(0,0,2437.80,3458.27); break;}
078          case 'RA1': {$size = array(0,0,1729.13,2437.80); break;}
079          case 'RA2': {$size = array(0,0,1218.90,1729.13); break;}
080          case 'RA3': {$size = array(0,0,864.57,1218.90); break;}
081          case 'RA4': {$size = array(0,0,609.45,864.57); break;}
082          case 'SRA0': {$size = array(0,0,2551.18,3628.35); break;}
083          case 'SRA1': {$size = array(0,0,1814.17,2551.18); break;}
084          case 'SRA2': {$size = array(0,0,1275.59,1814.17); break;}
085          case 'SRA3': {$size = array(0,0,907.09,1275.59); break;}
086          case 'SRA4': {$size = array(0,0,637.80,907.09); break;}
087          case 'LETTER': default: {$size = array(0,0,612.00,792.00); break;}
088          case 'LEGAL': {$size = array(0,0,612.00,1008.00); break;}
089          case 'EXECUTIVE': {$size = array(0,0,521.86,756.00); break;}
090          case 'FOLIO': {$size = array(0,0,612.00,936.00); break;}
091      }
092      switch (strtolower($orientation)){
093          case 'landscape':
094              $a=$size[3];
095              $size[3]=$size[2];
096              $size[2]=$a;
097              break;
098      }
099  } else {
100      if (count($paper)>2) {
101          // then an array was sent it to set the size
102          $size = $paper;
103      }
104      else { //size in centimeters has been passed
105          $size[0] = 0;
106          $size[1] = 0;
107          $size[2] = ( $paper[0] / 2.54 ) * 72;
108          $size[3] = ( $paper[1] / 2.54 ) * 72;
109      }
110  }
111  parent::__construct($size);
112  $this->ez['pageWidth']=$size[2];
113  $this->ez['pageHeight']=$size[3];
114 
115  // also set the margins to some reasonable defaults
116  $this->ez['topMargin']=30;
117  $this->ez['bottomMargin']=30;
118  $this->ez['leftMargin']=30;
119  $this->ez['rightMargin']=30;
120 
121  // set the current writing position to the top of the first page
122  $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
123  // and get the ID of the page that was created during the instancing process.
124  $this->ezPages[1]=$this->getFirstPageId();
125  $this->ezPageCount=1;
126  }
publiccurve ( x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 )[ cpdf ]
Parameters
requiredx0
requiredy0
requiredx1
requiredy1
requiredx2
requiredy2
requiredx3
requiredy3
Code
1666  function curve($x0,$y0,$x1,$y1,$x2,$y2,$x3,$y3){
1667    // in the current line style, draw a bezier curve from (x0,y0) to (x3,y3) using the other two points
1668    // as the control points for the curve.
1669    $this->objects[$this->currentContents]['c'].="\n".sprintf('%.3f',$x0).' '.sprintf('%.3f',$y0).' m '.sprintf('%.3f',$x1).' '.sprintf('%.3f',$y1);
1670    $this->objects[$this->currentContents]['c'].= ' '.sprintf('%.3f',$x2).' '.sprintf('%.3f',$y2).' '.sprintf('%.3f',$x3).' '.sprintf('%.3f',$y3).' c S';
1671  }
publicellipse ( x0 , y0 , r1 , r2 [0] , angle [0] , nSeg [8] , astart [0] , afinish [360] , close [1] , fill [0] )[ cpdf ]
Parameters
requiredx0
requiredy0
requiredr1
optionalr2 [0]
optionalangle [0]
optionalnSeg [8]
optionalastart [0]
optionalafinish [360]
optionalclose [1]
optionalfill [0]
Code
1697  function ellipse($x0,$y0,$r1,$r2=0,$angle=0,$nSeg=8,$astart=0,$afinish=360,$close=1,$fill=0){
1698    if ($r1==0){
1699      return;
1700    }
1701    if ($r2==0){
1702      $r2=$r1;
1703    }
1704    if ($nSeg<2){
1705      $nSeg=2;
1706    }
1707 
1708    $astart = deg2rad((float)$astart);
1709    $afinish = deg2rad((float)$afinish);
1710    $totalAngle =$afinish-$astart;
1711 
1712    $dt = $totalAngle/$nSeg;
1713    $dtm = $dt/3;
1714 
1715    if ($angle != 0){
1716      $a = -1*deg2rad((float)$angle);
1717      $tmp = "\n q ";
1718      $tmp .= sprintf('%.3f',cos($a)).' '.sprintf('%.3f',(-1.0*sin($a))).' '.sprintf('%.3f',sin($a)).' '.sprintf('%.3f',cos($a)).' ';
1719      $tmp .= sprintf('%.3f',$x0).' '.sprintf('%.3f',$y0).' cm';
1720      $this->objects[$this->currentContents]['c'].= $tmp;
1721      $x0=0;
1722      $y0=0;
1723    }
1724 
1725    $t1 = $astart;
1726    $a0 = $x0+$r1*cos($t1);
1727    $b0 = $y0+$r2*sin($t1);
1728    $c0 = -$r1*sin($t1);
1729    $d0 = $r2*cos($t1);
1730 
1731    $this->objects[$this->currentContents]['c'].="\n".sprintf('%.3f',$a0).' '.sprintf('%.3f',$b0).' m ';
1732    for ($i=1;$i<=$nSeg;$i++){
1733      // draw this bit of the total curve
1734      $t1 = $i*$dt+$astart;
1735      $a1 = $x0+$r1*cos($t1);
1736      $b1 = $y0+$r2*sin($t1);
1737      $c1 = -$r1*sin($t1);
1738      $d1 = $r2*cos($t1);
1739      $this->objects[$this->currentContents]['c'].="\n".sprintf('%.3f',($a0+$c0*$dtm)).' '.sprintf('%.3f',($b0+$d0*$dtm));
1740      $this->objects[$this->currentContents]['c'].= ' '.sprintf('%.3f',($a1-$c1*$dtm)).' '.sprintf('%.3f',($b1-$d1*$dtm)).' '.sprintf('%.3f',$a1).' '.sprintf('%.3f',$b1).' c';
1741      $a0=$a1;
1742      $b0=$b1;
1743      $c0=$c1;
1744      $d0=$d1;
1745    }
1746    if ($fill){
1747      $this->objects[$this->currentContents]['c'].=' f';
1748    } else {
1749      if ($close){
1750        $this->objects[$this->currentContents]['c'].=' s'; // small 's' signifies closing the path as well
1751      } else {
1752        $this->objects[$this->currentContents]['c'].=' S';
1753      }
1754    }
1755    if ($angle !=0){
1756      $this->objects[$this->currentContents]['c'].=' Q';
1757    }
1758  }
publicencryptInit ( id )[ cpdf ]
Parameters
requiredid
Code
1082  function encryptInit($id){
1083    $tmp = $this->encryptionKey;
1084    $hex = dechex($id);
1085    if (strlen($hex)<6){
1086      $hex = substr('000000',0,6-strlen($hex)).$hex;
1087    }
1088    $tmp.= chr(hexdec(substr($hex,4,2))).chr(hexdec(substr($hex,2,2))).chr(hexdec(substr($hex,0,2))).chr(0).chr(0);
1089    $key = $this->md5_16($tmp);
1090    $this->ARC4_init(substr($key,0,10));
1091  }
publicexecTemplate ( id , data [Array] , options [Array] )[ ezpdf ]
Parameters
requiredid
optionaldata [Array]
optionaloptions [Array]
Code
1459  public function execTemplate($id,$data=array(),$options=array()){
1460    // execute the given template on the current document.
1461    if (!isset($this->ez['templates'][$id])){
1462      return;
1463    }
1464    eval($this->ez['templates'][$id]['code']);
1465  }
publicezColumnsStart ( options [Array] )[ ezpdf ]
Parameters
optionaloptions [Array]
Code
141  public function ezColumnsStart($options=array()){
142    // start from the current y-position, make the set number of columne
143    if (isset($this->ez['columns']) && $this->ez['columns']==1){
144      // if we are already in a column mode then just return.
145      return;
146    }
147    $def=array('gap'=>10,'num'=>2);
148    foreach($def as $k=>$v){
149      if (!isset($options[$k])){
150        $options[$k]=$v;
151      }
152    }
153    // setup the columns
154    $this->ez['columns']=array('on'=>1,'colNum'=>1);
155 
156    // store the current margins
157    $this->ez['columns']['margins']=array(
158       $this->ez['leftMargin']
159      ,$this->ez['rightMargin']
160      ,$this->ez['topMargin']
161      ,$this->ez['bottomMargin']
162    );
163    // and store the settings for the columns
164    $this->ez['columns']['options']=$options;
165    // then reset the margins to suit the new columns
166    // safe enough to assume the first column here, but start from the current y-position
167    $this->ez['topMargin']=$this->ez['pageHeight']-$this->y;
168    $width=($this->ez['pageWidth']-$this->ez['leftMargin']-$this->ez['rightMargin']-($options['num']-1)*$options['gap'])/$options['num'];
169    $this->ez['columns']['width']=$width;
170    $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;
171   
172  }
publicezColumnsStop ( )[ ezpdf ]
Parameters
No parameters for this method
Code
174  public function ezColumnsStop(){
175    if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
176      $this->ez['columns']['on']=0;
177      $this->ez['leftMargin']=$this->ez['columns']['margins'][0];
178      $this->ez['rightMargin']=$this->ez['columns']['margins'][1];
179      $this->ez['topMargin']=$this->ez['columns']['margins'][2];
180      $this->ez['bottomMargin']=$this->ez['columns']['margins'][3];
181    }
182  }
publicezGetCurrentPageNumber ( )[ ezpdf ]
Parameters
No parameters for this method
Code
263  public function ezGetCurrentPageNumber(){
264    // return the strict numbering (1,2,3,4..) number of the current page
265    return $this->ezPageCount;
266  }
publicezImage ( image , pad [5] , width [0] , resize ["full"] , just ["center"] , border [""] )[ ezpdf ]
Parameters
requiredimage
optionalpad [5]
optionalwidth [0]
optionalresize ["full"]
optionaljust ["center"]
optionalborder [""]
Code
1298  public function ezImage($image,$pad = 5,$width = 0,$resize = 'full',$just = 'center',$border = ''){
1299  //beta ezimage function
1300  $temp = false;
1301  $offset = 0;
1302  if (stristr($image,'://'))//copy to temp file
1303  {
1304      $fp = @fopen($image,"rb");
1305      while(!feof($fp))
1306             {
1307                    $cont.= fread($fp,1024);
1308             }
1309             fclose($fp);
1310      $image = tempnam ("/tmp", "php-pdf");
1311      $fp2 = @fopen($image,"w");
1312             fwrite($fp2,$cont);
1313            fclose($fp2);
1314      $temp = true;
1315  }
1316 
1317  if (!(file_exists($image))) return false; //return immediately if image file does not exist
1318  $imageInfo = getimagesize($image);
1319  switch ($imageInfo[2]){
1320      case 2:
1321          $type = "jpeg";
1322          break;
1323      case 3:
1324          $type = "png";
1325          break;
1326      default:
1327          return false; //return if file is not jpg or png
1328  }
1329  if ($width == 0) $width = $imageInfo[0]; //set width
1330  $ratio = $imageInfo[0]/$imageInfo[1];
1331 
1332  //get maximum width of image
1333  if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
1334  {
1335      $bigwidth = $this->ez['columns']['width'] - ($pad * 2);
1336  }
1337  else
1338  {
1339      $bigwidth = $this->ez['pageWidth'] - ($pad * 2);
1340  }
1341  //fix width if larger than maximum or if $resize=full
1342  if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)
1343  {
1344      $width = $bigwidth;
1345 
1346  }
1347 
1348  $height = ($width/$ratio); //set height
1349 
1350  //fix size if runs off page
1351  if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))
1352  {
1353      if ($resize != 'full')
1354      {
1355          $this->ezNewPage();
1356      }
1357      else
1358      {
1359          $height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2)); //shrink height
1360          $width = ($height*$ratio); //fix width
1361      }
1362  }
1363 
1364  //fix x-offset if image smaller than bigwidth
1365  if ($width < $bigwidth)
1366  {
1367      //center if justification=center
1368      if ($just == 'center')
1369      {
1370          $offset = ($bigwidth - $width) / 2;
1371      }
1372      //move to right if justification=right
1373      if ($just == 'right')
1374      {
1375          $offset = ($bigwidth - $width);
1376      }
1377      //leave at left if justification=left
1378      if ($just == 'left')
1379      {
1380          $offset = 0;
1381      }
1382  }
1383 
1384 
1385  //call appropriate function
1386  if ($type == "jpeg"){
1387      $this->addJpegFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
1388  }
1389 
1390  if ($type == "png"){
1391      $this->addPngFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
1392  }
1393  //draw border
1394  if ($border != '')
1395  {
1396  if (!(isset($border['color'])))
1397  {
1398      $border['color']['red'] = .5;
1399      $border['color']['blue'] = .5;
1400      $border['color']['green'] = .5;
1401  }
1402  if (!(isset($border['width']))) $border['width'] = 1;
1403  if (!(isset($border['cap']))) $border['cap'] = 'round';
1404  if (!(isset($border['join']))) $border['join'] = 'round';
1405 
1406 
1407  $this->setStrokeColor($border['color']['red'],$border['color']['green'],$border['color']['blue']);
1408  $this->setLineStyle($border['width'],$border['cap'],$border['join']);
1409  $this->rectangle($this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width,$height);
1410 
1411  }
1412  // move y below image
1413  $this->y = $this->y - $pad - $height;
1414  //remove tempfile for remote images
1415  if ($temp == true) unlink($image);
1416 
1417  }
publicezInsertMode ( status [1] , pageNum [1] , pos ["before"] )[ ezpdf ]
Parameters
optionalstatus [1]
optionalpageNum [1]
optionalpos ["before"]
Code
184  public function ezInsertMode($status=1,$pageNum=1,$pos='before'){
185    // puts the document into insert mode. new pages are inserted until this is re-called with status=0
186    // by default pages wil be inserted at the start of the document
187    switch($status){
188      case '1':
189        if (isset($this->ezPages[$pageNum])){
190          $this->ez['insertMode']=1;
191          $this->ez['insertOptions']=array('id'=>$this->ezPages[$pageNum],'pos'=>$pos);
192        }
193        break;
194      case '0':
195        $this->ez['insertMode']=0;
196        break;
197    }
198  }
publicezNewPage ( )[ ezpdf ]
Parameters
No parameters for this method
Code
201  public function ezNewPage(){
202    $pageRequired=1;
203    if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
204      // check if this is just going to a new column
205      // increment the column number
206  //echo 'HERE<br>';
207      $this->ez['columns']['colNum']++;
208  //echo $this->ez['columns']['colNum'].'<br>';
209      if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num']){
210        // then just reset to the top of the next column
211        $pageRequired=0;
212      } else {
213        $this->ez['columns']['colNum']=1;
214        $this->ez['topMargin']=$this->ez['columns']['margins'][2];
215      }
216 
217      $width = $this->ez['columns']['width'];
218      $this->ez['leftMargin']=$this->ez['columns']['margins'][0]+($this->ez['columns']['colNum']-1)*($this->ez['columns']['options']['gap']+$width);
219      $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;
220    }
221  //echo 'left='.$this->ez['leftMargin'].'   right='.$this->ez['rightMargin'].'<br>';
222 
223    if ($pageRequired){
224      // make a new page, setting the writing point back to the top
225      $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
226      // make the new page with a call to the basic class.
227      $this->ezPageCount++;
228      if (isset($this->ez['insertMode']) && $this->ez['insertMode']==1){
229        $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1,$this->ez['insertOptions']['id'],$this->ez['insertOptions']['pos']);
230        // then manipulate the insert options so that inserted pages follow each other
231        $this->ez['insertOptions']['id']=$id;
232        $this->ez['insertOptions']['pos']='after';
233      } else {
234        $this->ezPages[$this->ezPageCount] = $this->newPage();
235      }
236    } else {
237      $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];
238    }
239  }
publicezOutput ( options [0] )[ ezpdf ]
Parameters
optionaloptions [0]
Code
458  public function ezOutput($options=0){
459    $this->ezPRVTcleanUp();
460    return $this->output($options);
461  }
publicezPRVTaddPageNumbers ( )[ ezpdf ]
Parameters
No parameters for this method
Code
374  public function ezPRVTaddPageNumbers(){
375    // this will go through the pageNumbering array and add the page numbers are required
376    if (isset($this->ez['pageNumbering'])){
377      $totalPages1 = $this->ezPageCount;
378      $tmp1=$this->ez['pageNumbering'];
379      $status=0;
380      foreach($tmp1 as $i=>$tmp){
381        // do each of the page numbering systems
382        // firstly, find the total pages for this one
383        $k = $this->ezPRVTpageNumberSearch('stopt',$tmp);
384        if ($k && $k>0){
385          $totalPages = $k-1;
386        } else {
387          $l = $this->ezPRVTpageNumberSearch('stoptn',$tmp);
388          if ($l && $l>0){
389            $totalPages = $l;
390          } else {
391            $totalPages = $totalPages1;
392          }
393        }
394        foreach ($this->ezPages as $pageNum=>$id){
395          if (isset($tmp[$pageNum])){
396            if (is_array($tmp[$pageNum])){
397              // then this must be starting page numbers
398              $status=1;
399              $info = $tmp[$pageNum];
400              $info['dnum']=$info['num']-$pageNum;
401              // also check for the special case of the numbering stopping and starting on the same page
402              if (isset($info['stopn']) || isset($info['stoptn']) ){
403                $status=2;
404              }
405            } else if ($tmp[$pageNum]=='stop' || $tmp[$pageNum]=='stopt'){
406              // then we are stopping page numbers
407              $status=0;
408            } else if ($status==1 && ($tmp[$pageNum]=='stoptn' || $tmp[$pageNum]=='stopn')){
409              // then we are stopping page numbers
410              $status=2;
411            }
412          }
413          if ($status){
414            // then add the page numbering to this page
415            if (strlen($info['num'])){
416              $num=$pageNum+$info['dnum'];
417            } else {
418              $num=$pageNum;
419            }
420            $total = $totalPages+$num-$pageNum;
421            $pat = str_replace('{PAGENUM}',$num,$info['pattern']);
422            $pat = str_replace('{TOTALPAGENUM}',$total,$pat);
423            $this->reopenObject($id);
424            switch($info['pos']){
425              case 'right':
426                $this->addText($info['x'],$info['y'],$info['size'],$pat);
427                break;
428              default:
429                $w=$this->getTextWidth($info['size'],$pat);
430                $this->addText($info['x']-$w,$info['y'],$info['size'],$pat);
431                break;
432            }
433            $this->closeObject();
434          }
435          if ($status==2){
436            $status=0;
437          }
438        }
439      }
440    }
441  }
publicezPRVTcleanUp ( )[ ezpdf ]
Parameters
No parameters for this method
Code
445  public function ezPRVTcleanUp(){
446    $this->ezPRVTaddPageNumbers();
447  }
publicezPRVTpageNumberSearch ( lbl , &tmp )[ ezpdf ]
Parameters
requiredlbl
required&tmp
Code
357  public function ezPRVTpageNumberSearch($lbl,&$tmp){
358    foreach($tmp as $i=>$v){
359      if (is_array($v)){
360        if (isset($v[$lbl])){
361          return $i;
362        }
363      } else {
364        if ($v==$lbl){
365          return $i;
366        }
367      }
368    }
369    return 0;
370  }
publicezProcessText ( text )[ ezpdf ]
Parameters
requiredtext
Code
1192  public function ezProcessText($text){
1193    // this function will intially be used to implement underlining support, but could be used for a range of other
1194    // purposes
1195    $search = array('<u>','<U>','</u>','</U>');
1196    $replace = array('<c:uline>','<c:uline>','</c:uline>','</c:uline>');
1197    return str_replace($search,$replace,$text);
1198  }
publicezPrvtGetTextWidth ( size , text )[ ezpdf ]
Parameters
requiredsize
requiredtext
Code
588  public function ezPrvtGetTextWidth($size,$text){
589    // will calculate the maximum width, taking into account that the text may be broken
590    // by line breaks.
591    $mx=0;
592    $lines = explode("\n",$text);
593    foreach ($lines as $line){
594      $w = $this->getTextWidth($size,$line);
595      if ($w>$mx){
596        $mx=$w;
597      }
598    }
599    return $mx;
600  }
publicezPrvtTableColumnHeadings ( cols , pos , maxWidth , height , decender , gap , size , &y , optionsAll [Array] )[ ezpdf ]
Parameters
requiredcols
requiredpos
requiredmaxWidth
requiredheight
requireddecender
requiredgap
requiredsize
required&y
optionaloptionsAll [Array]
Code
523  public function ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$gap,$size,&$y,$optionsAll=array()){
524    // uses ezText to add the text, and returns the height taken by the largest heading
525    // this page will move the headings to a new page if they will not fit completely on this one
526    // transaction support will be used to implement this
527 
528    if (isset($optionsAll['cols'])){
529      $options = $optionsAll['cols'];
530    } else {
531      $options = array();
532    }
533   
534    $mx=0;
535    $startPage = $this->ezPageCount;
536    $secondGo=0;
537 
538    // $y is the position at which the top of the table should start, so the base
539    // of the first text, is $y-$height-$gap-$decender, but ezText starts by dropping $height
540   
541    // the return from this function is the total cell height, including gaps, and $y is adjusted
542    // to be the postion of the bottom line
543   
544    // begin the transaction
545    $this->transaction('start');
546    $ok=0;
547  //  $y-=$gap-$decender;
548    $y-=$gap;
549    while ($ok==0){
550      foreach($cols as $colName=>$colHeading){
551        $this->ezSetY($y);
552        if (isset($options[$colName]) && isset($options[$colName]['justification'])){
553          $justification = $options[$colName]['justification'];
554        } else {
555          $justification = 'left';
556        }
557        $this->ezText($colHeading,$size,array('aleft'=> $pos[$colName],'aright'=>($maxWidth[$colName]+$pos[$colName]),'justification'=>$justification));
558        $dy = $y-$this->y;
559        if ($dy>$mx){
560          $mx=$dy;
561        }
562      }
563      $y = $y - $mx - $gap + $decender;
564  //    $y -= $mx-$gap+$decender;
565     
566      // now, if this has moved to a new page, then abort the transaction, move to a new page, and put it there
567      // do not check on the second time around, to avoid an infinite loop
568      if ($this->ezPageCount != $startPage && $secondGo==0){
569        $this->transaction('rewind');
570        $this->ezNewPage();
571        $y = $this->y - $gap-$decender;
572        $ok=0;
573        $secondGo=1;
574  //      $y = $store_y;
575        $mx=0;
576 
577      } else {
578        $this->transaction('commit');
579        $ok=1;
580      }
581    }
582 
583    return $mx+$gap*2-$decender;
584  }
publicezPrvtTableDrawLines ( pos , gap , x0 , x1 , y0 , y1 , y2 , col , inner , outer , opt [1] )[ ezpdf ]
Parameters
requiredpos
requiredgap
requiredx0
requiredx1
requiredy0
requiredy1
requiredy2
requiredcol
requiredinner
requiredouter
optionalopt [1]
Code
494  public function ezPrvtTableDrawLines($pos,$gap,$x0,$x1,$y0,$y1,$y2,$col,$inner,$outer,$opt=1){
495    $x0=1000;
496    $x1=0;
497    $this->setStrokeColor($col[0],$col[1],$col[2]);
498    $cnt=0;
499    $n = count($pos);
500    foreach($pos as $x){
501