eaiovnaovbqoebvqoeavibavo license.txt 0000644 00000000513 15021755450 0006732 0 ustar 00 Permission is hereby granted, free of charge, to any person obtaining a copy of this software to use, copy, modify, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. changelog.htm 0000644 00000022140 15021755450 0007210 0 ustar 00
SetCompression(boolean compress)
compress
float GetX()
Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])
file
x
null
, se utilizar la abscisa actual.
y
null
, se utilizar la ordenada actual, adems,
un salto de pgina es invocado primero si es necesario (en caso de que est habilitado el salto de pgina automtico) y, despus de la llamada,
la ordenada actual se mueve a la parte inferior de la imagen.
w
h
type
JPG
, JPEG
, PNG
y GIF
.
Si no se especifica, el tipo se deduce de la extensin del fichero.
link
// Inserta un logo en la esquina superior izquierda a 300 ppp
$pdf->Image('logo.png',10,10,-300);
// Inserta una imagen dinmica a travs de una URL
$pdf->Image('http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World',60,30,90,0,'PNG');
float GetPageWidth()
Rect(float x, float y, float w, float h [, string style])
x
y
w
h
style
D
o una cadena vacia: draw. Este es el valor por defecto.
F
: fill
DF
o FD
: draw and fill
SetFillColor(int r [, int g, int b])
r
g
y b
se establecen, componente rojo; si no, indica el nivel de gris.
Valor entre 0 y 255.
g
b
AddFont(string family [, string style [, string file]])
family
style
B
: bold (negrita)
I
: italic (cursiva)
BI
o IB
: bold italic (negrita cursiva)
file
$pdf->AddFont('Comic','I');
$pdf->AddFont('Comic','I','comici.php');
float GetY()
int AddLink()
SetAuthor(string author [, boolean isUTF8])
author
isUTF8
false
) o UTF-8 (true
).false
.
SetCreator(string creator [, boolean isUTF8])
creator
isUTF8
false
) o UTF-8 (true
).false
.
Line(float x1, float y1, float x2, float y2)
x1
y1
x2
y2
MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])
w
0
, estos se extienden hasta l mrgen derecha de la pgina.
h
txt
border
0
: no borde1
: marcoL
: izquierdaT
: superiorR
: derechaB
: inferior0
.
align
L
: alineacin a la izquierdaC
: centradoR
: alineacin a la derechaJ
: justificacin (valor por defecto)fill
true
) o transparente (false
).
Valor por defecto: false
.
Write(float h, string txt [, mixed link])
h
txt
link
// Comienza con fuente regular
$pdf->SetFont('Arial','',14);
$pdf->Write(5,'Visit ');
// Then put a blue underlined link
$pdf->SetTextColor(0,0,255);
$pdf->SetFont('','U');
$pdf->Write(5,'www.fpdf.org','http://www.fpdf.org');
string Output([string dest [, string name [, boolean isUTF8]]])
dest
I
: enva el fichero al navegador de forma que se usa la extensin (plug in) si est disponible.D
: enva el fichero al navegador y fuerza la descarga del fichero con el nombre especificado por name
.F
: guarda el fichero en un fichero local de nombre name
.S
: devuelve el documento como una cadena.I
.
name
S
.doc.pdf
.
isUTF8
name
es codificado en ISO-8859-1 (false
) UTF-8 (true
).
Solo usa destinos I
y D
.false
.
SetTextColor(int r [, int g, int b])
r
g
y b
son suministrados, componente rojo; si no, indica el nivel de grises.
Valor entre 0 y 255.
g
b
Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])
w
0
, la celda se extiende hasta la mrgen derecha.
h
0
.
txt
border
0
: sin borde1
: marcoL
: izquierdaT
: superiorR
: derechaB
: inferior0
.
ln
0
: a la derecha1
: al comienzo de la siguiente lnea2
: debajo1
es equivalente a poner 0
y llamar justo despues Ln().
Valor por defecto: 0
.
align
L
o una cadena vacia: alineacin izquierda (valor por defecto)C
: centroR
: alineacin derechafill
true
) o transparente (false
).
Valor por defecto: false
.
link
// Set font
$pdf->SetFont('Arial','B',16);
// Move to 8 cm to the right
$pdf->Cell(80);
// Texto centrado en una celda con cuadro 20*10 mm y salto de lnea
$pdf->Cell(20,10,'Title',1,1,'C');
SetLink(int link [, float y [, int page]])
link
y
-1
indica la posicin actual.
El valor por defecto es 0
(parte superior de la pgina).
page
-1
indica la pgina actual. Este es el valor por defecto.
SetKeywords(string keywords [, boolean isUTF8])
keywords
isUTF8
false
) o UTF-8 (true
).false
.
SetMargins(float left, float top [, float right])
left
top
right
AddPage([string orientation [, mixed size [, int rotation]]])
orientation
P
o Portrait
(normal)L
o Landscape
(apaisado)size
A3
A4
A5
Letter
Legal
rotation
0
.
SetSubject(string subject [, boolean isUTF8])
subject
isUTF8
false
) o UTF-8 (true
).false
.
float GetPageHeight()
Link(float x, float y, float w, float h, mixed link)
x
y
w
h
link
Error(string msg)
msg
SetTopMargin(float margin)
margin
__construct([string orientation [, string unit [, mixed size]]])
orientation
P
o Portrait
(normal)
L
o Landscape
(apaisado)
P
.
unit
pt
: punto
mm
: milimetro
cm
: centimetro
in
: pulgada
mm
.
size
A3
A4
A5
Letter
Legal
unit
).
A4
.
$pdf = new FPDF('P','mm',array(100,150));
SetFont(string family [, string style [, float size]])
FPDF_FONTPATH
(si es que ha sido definida)
include()
define('FPDF_FONTPATH','/home/www/font');
require('fpdf.php');
family
Courier
(fixed-width)
Helvetica
o Arial
(sinnimo; sans serif)
Times
(serif)
Symbol
(symbolic)
ZapfDingbats
(symbolic)
style
B
: bold
I
: italic
U
: underline
Symbol
y ZapfDingbats
.
size
// Times regular 12
$pdf->SetFont('Times');
// Arial bold 14
$pdf->SetFont('Arial','B',14);
// Elimina bold
$pdf->SetFont('');
// Times bold, italic y underlined 14
$pdf->SetFont('Times','BIU');
boolean AcceptPageBreak()
class PDF extends FPDF
{
var $col = 0;
function SetCol($col)
{
// Move position to a column
$this->col = $col;
$x = 10+$col*65;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
if($this->col<2)
{
// Go to next column
$this->SetCol($this->col+1);
$this->SetY(10);
return false;
}
else
{
// Regrese a la primera columna y emita un salto de pgina
$this->SetCol(0);
return true;
}
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',12);
for($i=1;$i<=300;$i++)
$pdf->Cell(0,5,"Line $i",0,1);
$pdf->Output();
int PageNo()
Close()
SetDrawColor(int r [, int g, int b])
r
g
y b
son suministrados, componente rojo; si no, si no indica nivel de grises.
Valores entre 0 y 255.
g
b
Footer()
class PDF extends FPDF
{
function Footer()
{
// Go to 1.5 cm from bottom
$this->SetY(-15);
// Select Arial italic 8
$this->SetFont('Arial','I',8);
// Print centered page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
}
SetAutoPageBreak(boolean auto [, float margin])
auto
margin
Text(float x, float y, string txt)
x
y
txt
AliasNbPages([string alias])
alias
{nb}
.
class PDF extends FPDF
{
function Footer()
{
// Go to 1.5 cm from bottom
$this->SetY(-15);
// Select Arial italic 8
$this->SetFont('Arial','I',8);
// Print current and total page numbers
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$pdf = new PDF();
$pdf->AliasNbPages();
SetLeftMargin(float margin)
margin
Ln([float h])
h
float GetStringWidth(string s)
s
Header()
class PDF extends FPDF
{
function Header()
{
// Select Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Framed title
$this->Cell(30,10,'Title',1,0,'C');
// Line break
$this->Ln(20);
}
}
SetY(float y [, boolean resetX])
y
resetX
true
.
SetRightMargin(float margin)
margin
SetFontSize(float size)
size
SetX(float x)
x
SetTitle(string title [, boolean isUTF8])
title
isUTF8
false
) o UTF-8 (true
).false
.
SetDisplayMode(mixed zoom [, string layout])
zoom
fullpage
: despliega la pgina completa en la pantalla
fullwidth
: usa el ancho mximo de la pantalla
real
: usa el tamao real (equivalente a un acercamiento de 100% )
default
: usa el modo por defecto del visor
layout
single
: despliega una pgina la tiempo
continuous
: despliega pginas continuamente
two
: despliega dos pginas en dos columnas
default
: usa el modo por defecto del visor
default
.
SetLineWidth(float width)
width
SetXY(float x, float y)
x
y
<?php
require('fpdf.php');
class PDF extends FPDF
{
protected $col = 0; // Columna actual
protected $y0; // Ordenada de comienzo de la columna
function Header()
{
// Cabacera
global $title;
$this->SetFont('Arial','B',15);
$w = $this->GetStringWidth($title)+6;
$this->SetX((210-$w)/2);
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
$this->SetLineWidth(1);
$this->Cell($w,9,$title,1,1,'C',true);
$this->Ln(10);
// Guardar ordenada
$this->y0 = $this->GetY();
}
function Footer()
{
// Pie de pgina
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->SetTextColor(128);
$this->Cell(0,10,'Pgina '.$this->PageNo(),0,0,'C');
}
function SetCol($col)
{
// Establecer la posicin de una columna dada
$this->col = $col;
$x = 10+$col*65;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
// Mtodo que acepta o no el salto automtico de pgina
if($this->col<2)
{
// Ir a la siguiente columna
$this->SetCol($this->col+1);
// Establecer la ordenada al principio
$this->SetY($this->y0);
// Seguir en esta pgina
return false;
}
else
{
// Volver a la primera columna
$this->SetCol(0);
// Salto de pgina
return true;
}
}
function ChapterTitle($num, $label)
{
// Ttulo
$this->SetFont('Arial','',12);
$this->SetFillColor(200,220,255);
$this->Cell(0,6,"Captulo $num : $label",0,1,'L',true);
$this->Ln(4);
// Guardar ordenada
$this->y0 = $this->GetY();
}
function ChapterBody($file)
{
// Abrir fichero de texto
$txt = file_get_contents($file);
// Fuente
$this->SetFont('Times','',12);
// Imprimir texto en una columna de 6 cm de ancho
$this->MultiCell(60,5,$txt);
$this->Ln();
// Cita en itlica
$this->SetFont('','I');
$this->Cell(0,5,'(fin del extracto)');
// Volver a la primera columna
$this->SetCol(0);
}
function PrintChapter($num, $title, $file)
{
// Aadir captulo
$this->AddPage();
$this->ChapterTitle($num,$title);
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leguas de Viaje Submarino';
$pdf->SetTitle($title);
$pdf->SetAuthor('Julio Verne');
$pdf->PrintChapter(1,'UN RIZO DE HUIDA','20k_c1.txt');
$pdf->PrintChapter(2,'LOS PROS Y LOS CONTRAS','20k_c2.txt');
$pdf->Output();
?>
<?php
require('fpdf.php');
class PDF extends FPDF
{
// Cabecera de pgina
function Header()
{
// Logo
$this->Image('logo_pb.png',10,8,33);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Movernos a la derecha
$this->Cell(80);
// Ttulo
$this->Cell(30,10,'Title',1,0,'C');
// Salto de lnea
$this->Ln(20);
}
// Pie de pgina
function Footer()
{
// Posicin: a 1,5 cm del final
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Nmero de pgina
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// Creacin del objeto de la clase heredada
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Imprimiendo lnea nmero '.$i,0,1);
$pdf->Output();
?>
{nb}
que ser sustituido cuando se cierre el documento (suponiendo que
usted antes utilizara AliasNbPages()).
<?php
require('fpdf.php');
class PDF extends FPDF
{
// Cargar los datos
function LoadData($file)
{
// Leer las lneas del fichero
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';',trim($line));
return $data;
}
// Tabla simple
function BasicTable($header, $data)
{
// Cabecera
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
// Datos
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
// Una tabla ms completa
function ImprovedTable($header, $data)
{
// Anchuras de las columnas
$w = array(40, 35, 45, 40);
// Cabeceras
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
// Datos
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
$this->Ln();
}
// Lnea de cierre
$this->Cell(array_sum($w),0,'','T');
}
// Tabla coloreada
function FancyTable($header, $data)
{
// Colores, ancho de lnea y fuente en negrita
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Cabecera
$w = array(40, 35, 45, 40);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Restauracin de colores y fuentes
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Datos
$fill = false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Lnea de cierre
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf = new PDF();
// Ttulos de las columnas
$header = array('Pas', 'Capital', 'Superficie (km2)', 'Pobl. (en miles)');
// Carga de datos
$data = $pdf->LoadData('paises.txt');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data);
$pdf->AddPage();
$pdf->ImprovedTable($header,$data);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>
border
del mtodo Cell(), que especifica qu bordes de la celda deben imprimirse.
En este caso, queremos que sean los de la izquierda (L
) y los de la derecha
(R
). Seguimos teniendo el problema de la lnea horizontal de fin de tabla.
Hay dos posibilidades: o comprobar si estamos en la ltima lnea en el bucle, en cuyo caso
usaremos LRB
para el parmtro border
; o, como hemos hecho aqu,
aadir la lnea una vez que el bucle ha terminado.