Tema: generar pdf
Ver Mensaje Individual
  #10 (permalink)  
Antiguo 02/12/2004, 12:11
Avatar de The_omars
The_omars
 
Fecha de Ingreso: marzo-2004
Mensajes: 271
Antigüedad: 20 años, 1 mes
Puntos: 0
Código PHP:
function AddPage($orientation='')
{
    
//Start a new page
    
if($this->state==0)
        
$this->Open();
    
$family=$this->FontFamily;
    
$style=$this->FontStyle.($this->underline 'U' '');
    
$size=$this->FontSizePt;
    
$lw=$this->LineWidth;
    
$dc=$this->DrawColor;
    
$fc=$this->FillColor;
    
$tc=$this->TextColor;
    
$cf=$this->ColorFlag;
    if(
$this->page>0)
    {
        
//Page footer
        
$this->InFooter=true;
        
$this->Footer();
        
$this->InFooter=false;
        
//Close page
        
$this->_endpage();
    }
    
//Start new page
    
$this->_beginpage($orientation);
    
//Set line cap style to square
    
$this->_out('2 J');
    
//Set line width
    
$this->LineWidth=$lw;
    
$this->_out(sprintf('%.2f w',$lw*$this->k));
    
//Set font
    
if($family)
        
$this->SetFont($family,$style,$size);
    
//Set colors
    
$this->DrawColor=$dc;
    if(
$dc!='0 G')
        
$this->_out($dc);
    
$this->FillColor=$fc;
    if(
$fc!='0 g')
        
$this->_out($fc);
    
$this->TextColor=$tc;
    
$this->ColorFlag=$cf;
    
//Page header
    
$this->Header();
    
//Restore line width
    
if($this->LineWidth!=$lw)
    {
        
$this->LineWidth=$lw;
        
$this->_out(sprintf('%.2f w',$lw*$this->k));
    }
    
//Restore font
    
if($family)
        
$this->SetFont($family,$style,$size);
    
//Restore colors
    
if($this->DrawColor!=$dc)
    {
        
$this->DrawColor=$dc;
        
$this->_out($dc);
    }
    if(
$this->FillColor!=$fc)
    {
        
$this->FillColor=$fc;
        
$this->_out($fc);
    }
    
$this->TextColor=$tc;
    
$this->ColorFlag=$cf;
}

function 
Header()
{
    
//To be implemented in your own inherited class
}

function 
Footer()
{
    
//To be implemented in your own inherited class
}

function 
PageNo()
{
    
//Get current page number
    
return $this->page;
}

function 
SetDrawColor($r,$g=-1,$b=-1)
{
    
//Set color for all stroking operations
    
if(($r==and $g==and $b==0) or $g==-1)
        
$this->DrawColor=sprintf('%.3f G',$r/255);
    else
        
$this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
    if(
$this->page>0)
        
$this->_out($this->DrawColor);
}

function 
SetFillColor($r,$g=-1,$b=-1)
{
    
//Set color for all filling operations
    
if(($r==and $g==and $b==0) or $g==-1)
        
$this->FillColor=sprintf('%.3f g',$r/255);
    else
        
$this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
    
$this->ColorFlag=($this->FillColor!=$this->TextColor);
    if(
$this->page>0)
        
$this->_out($this->FillColor);
}

function 
SetTextColor($r,$g=-1,$b=-1)
{
    
//Set color for text
    
if(($r==and $g==and $b==0) or $g==-1)
        
$this->TextColor=sprintf('%.3f g',$r/255);
    else
        
$this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
    
$this->ColorFlag=($this->FillColor!=$this->TextColor);
}

function 
GetStringWidth($s)
{
    
//Get width of a string in the current font
    
$s=(string)$s;
    
$cw=&$this->CurrentFont['cw'];
    
$w=0;
    
$l=strlen($s);
    for(
$i=0;$i<$l;$i++)
        
$w+=$cw[$s{$i}];
    return 
$w*$this->FontSize/1000;
}

function 
SetLineWidth($width)
{
    
//Set line width
    
$this->LineWidth=$width;
    if(
$this->page>0)
        
$this->_out(sprintf('%.2f w',$width*$this->k));
}

function 
Line($x1,$y1,$x2,$y2)
{
    
//Draw a line
    
$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
}

function 
Rect($x,$y,$w,$h,$style='')
{
    
//Draw a rectangle
    
if($style=='F')
        
$op='f';
    elseif(
$style=='FD' or $style=='DF')
        
$op='B';
    else
        
$op='S';
    
$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
}

function 
AddFont($family,$style='',$file='')
{
    
//Add a TrueType or Type1 font
    
$family=strtolower($family);
    if(
$family=='arial')
        
$family='helvetica'
    
$style=strtoupper($style);        
    if(
$style=='IB')
        
$style='BI';
    if(isset(
$this->fonts[$family.$style]))
        
$this->Error('Font already added: '.$family.' '.$style);
    if(
$file=='')
        
$file=str_replace(' ','',$family).strtolower($style).'.php';
    if(
defined('FPDF_FONTPATH'))
        
$file=FPDF_FONTPATH.$file;
    include(
$file);
    if(!isset(
$name))
        
$this->Error('Could not include font definition file');
    
$i=count($this->fonts)+1;
    
$this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file);
    if(
$diff)
    {
        
//Search existing encodings
        
$d=0;
        
$nb=count($this->diffs);
        for(
$i=1;$i<=$nb;$i++)
            if(
$this->diffs[$i]==$diff)
            {
                
$d=$i;
                break;
            }
        if(
$d==0)
        {
            
$d=$nb+1;
            
$this->diffs[$d]=$diff;
        }
        
$this->fonts[$family.$style]['diff']=$d;
    }
    if(
$file)
    {
        if(
$type=='TrueType')
            
$this->FontFiles[$file]=array('length1'=>$originalsize);
        else
            
$this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
    }
}

function 
SetFont($family,$style='',$size=0)
{
    
//Select a font; size given in points
    
global $fpdf_charwidths;

    
$family=strtolower($family);
    if(
$family=='')
        
$family=$this->FontFamily;
    if(
$family=='arial')
        
$family='helvetica';
    elseif(
$family=='symbol' or $family=='zapfdingbats')
        
$style='';
    
$style=strtoupper($style);
    if(
is_int(strpos($style,'U')))
    {
        
$this->underline=true;
        
$style=str_replace('U','',$style);
    }
    else
        
$this->underline=false;
    if(
$style=='IB')
        
$style='BI';
    if(
$size==0)
        
$size=$this->FontSizePt;
    
//Test if font is already selected
    
if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size)
        return;
    
//Test if used for the first time
    
$fontkey=$family.$style;
    if(!isset(
$this->fonts[$fontkey]))
    {
        
//Check if one of the standard fonts
        
if(isset($this->CoreFonts[$fontkey]))
        {
            if(!isset(
$fpdf_charwidths[$fontkey]))
            {
                
//Load metric file
                
$file=$family;
                if(
$family=='times' or $family=='helvetica')
                    
$file.=strtolower($style);
                
$file.='.php';
                if(
defined('FPDF_FONTPATH'))
                    
$file=FPDF_FONTPATH.$file;
                include(
$file);
                if(!isset(
$fpdf_charwidths[$fontkey]))
                    
$this->Error('Could not include font metric file');
            }
            
$i=count($this->fonts)+1;
            
$this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]);
        }
        else
            
$this->Error('Undefined font: '.$family.' '.$style);
    }
    
//Select it
    
$this->FontFamily=$family;
    
$this->FontStyle=$style;
    
$this->FontSizePt=$size;
    
$this->FontSize=$size/$this->k;
    
$this->CurrentFont=&$this->fonts[$fontkey];
    if(
$this->page>0)
        
$this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}

function 
SetFontSize($size)
{
    
//Set font size in points
    
if($this->FontSizePt==$size)
        return;
    
$this->FontSizePt=$size;
    
$this->FontSize=$size/$this->k;
    if(
$this->page>0)
        
$this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}

function 
AddLink()
{
    
//Create a new internal link
    
$n=count($this->links)+1;
    
$this->links[$n]=array(0,0);
    return 
$n;
}

function 
SetLink($link,$y=0,$page=-1)
{
    
//Set destination of internal link
    
if($y==-1)
        
$y=$this->y;
    if(
$page==-1)
        
$page=$this->page;
    
$this->links[$link]=array($page,$y);
}

function 
Link($x,$y,$w,$h,$link)
{
    
//Put a link on the page
    
$this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
}

function 
Text($x,$y,$txt)
{
    
//Output a string
    
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    if(
$this->underline and $txt!='')
        
$s.=' '.$this->_dounderline($x,$y,$txt);
    if(
$this->ColorFlag)
        
$s='q '.$this->TextColor.' '.$s.' Q';
    
$this->_out($s);
}

function 
AcceptPageBreak()
{
    
//Accept automatic page break or not
    
return $this->AutoPageBreak;
}

*** 
continua 

Última edición por The_omars; 02/12/2004 a las 12:13