php-fpdf_1.8.4.dfsg.orig/ 0000755 0001750 0001750 00000000000 14150653761 015443 5 ustar adezorzi adezorzi php-fpdf_1.8.4.dfsg.orig/changelog.htm 0000644 0001750 0001750 00000022462 14112400706 020075 0 ustar adezorzi adezorzi
boolean AcceptPageBreak()
class PDF extends FPDF
{
var $col = 0;
function SetCol($col)
{
// Muove la posizione ad una colonna
$this->col = $col;
$x = 10+$col*65;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
if($this->col<2)
{
// Va alla colonna successiva
$this->SetCol($this->col+1);
$this->SetY(10);
return false;
}
else
{
// Ritorna alla prima colonna ed esegue una interruzione di pagina
$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();
AddFont(string family [, string style [, string file]])
family
style
B
: grassettoI
: corsivoBI
o IB
: grassetto corsivofile
$pdf->AddFont('Comic','I');
$pdf->AddFont('Comic','I','comici.php');
int AddLink()
AddPage([string orientation [, mixed size [, int rotation]]])
orientation
P
o Portrait
L
o Landscape
size
A3
A4
A5
Letter
Legal
unit
).
A4
.
rotation
0
.
AliasNbPages([string alias])
alias
{nb}
.
class PDF extends FPDF
{
function Footer()
{
// Va a 1.5 cm dal fondo della pagina
$this->SetY(-15);
// Seleziona Arial corsivo 8
$this->SetFont('Arial','I',8);
// Stampa il numero di pagina corrente e totale
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$pdf = new PDF();
$pdf->AliasNbPages();
Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])
w
0
, la cella si estende dalla parte del margine destro.
h
0
.
txt
border
0
: nessun bordo1
: corniceL
: sinistroT
: superioreR
: destroB
: inferiore0
.
ln
0
: a destra1
: all'inizio della linea successiva2
: in basso1
equivale a inserire 0
e chiamare Ln() immediatamente dopo.
Valore di default: 0
.
align
L
o stringa vuota: allineamento a sinistra (valore di default)C
: centratoR
: allineamento a destrafill
true
) o deve essere
trasparente (false
).
Valore di default: false
.
link
// Imposta il font
$pdf->SetFont('Arial','B',16);
// Muove a 8 cm dalla destra
$pdf->Cell(80);
// Testo centrato in una cella di 20*10 mm e interruzione di linea
$pdf->Cell(20,10,'Title',1,1,'C');
Close()
Error(string msg)
msg
Footer()
class PDF extends FPDF
{
function Footer()
{
// Va a 1.5 cm dal fondo della pagina
$this->SetY(-15);
// Seleziona Arial corsivo 8
$this->SetFont('Arial','I',8);
// Stampa il numero di pagina centrato
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
}
float GetPageHeight()
float GetPageWidth()
float GetStringWidth(string s)
s
float GetX()
float GetY()
Header()
class PDF extends FPDF
{
function Header()
{
// Seleziona Arial grassetto 15
$this->SetFont('Arial','B',15);
// Muove verso destra
$this->Cell(80);
// Titolo in riquadro
$this->Cell(30,10,'Title',1,0,'C');
// Interruzione di linea
$this->Ln(20);
}
}
Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])
file
x
null
, viene utilizzata
l'ascissa corrente.
y
null
, viene utilizzata
l'ordinata corrente; inoltre, se necessario, prima viene inserita un'interruzione di pagina (in caso
fosse abilita l'interruzione di pagina automatica) e, dopo la chiamata, le coordinate correnti vengono
spostate al di sotto dell'immagine.
w
h
type
JPG
, JPEG
, PNG
e
GIF
.
Se non specificato, il tipo sarà riferito all'estensione del file.
link
// Inserisce il logo nell'angolo in alto a sinistra, con risoluzione di 300 dpi
$pdf->Image('logo.png',10,10,-300);
// Inserisce un'immagine dinamica da URL
$pdf->Image('http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World',60,30,90,0,'PNG');
Line(float x1, float y1, float x2, float y2)
x1
y1
x2
y2
Link(float x, float y, float w, float h, mixed link)
x
y
w
h
link
Ln([float h])
h
MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])
w
0
, si estendono dalla parte del margine destro della pagina.
h
txt
border
0
: nessun bordo1
: corniceL
: sinistroT
: superioreR
: destroB
: inferiore0
.
align
L
: allineamento a sinistraC
: centratoR
: allienamento a destraJ
: giustificazione (valore di default)fill
true
) o deve essere
trasparente (false
).
Valore di default: false
.
string Output([string dest [, string name [, boolean isUTF8]]])
dest
I
: manda il 'file inline' al browser. Il plug-in sarà utilizzato se presente.D
: manda al browser e forza il download del file con il nome dato con name
.F
: salva il file in locale con il nome dato con name
.S
: ritorna il documento come stringa.I
.
name
S
.doc.pdf
.
isUTF8
name
segue la codifica ISO-8859-1 (false
) o UTF-8 (true
).
Usato solo per le destinazioni I
e D
.false
.
int PageNo()
Rect(float x, float y, float w, float h [, string style])
x
y
w
h
style
D
o una stringa vuota: disegna. E' il valore di default.F
: riempieDF
o FD
: disegna e riempieSetAuthor(string author [, boolean isUTF8])
author
isUTF8
false
) o UTF-8 (true
).false
.
SetAutoPageBreak(boolean auto [, float margin])
auto
margin
SetCompression(boolean compress)
compress
SetCreator(string creator [, boolean isUTF8])
creator
isUTF8
false
) o UTF-8 (true
).false
.
SetDisplayMode(mixed zoom [, string layout])
zoom
fullpage
: mostra a schermo l'intera paginafullwidth
: a tutta paginareal
: utilizza le dimensioni reali (equivalente a zoom=100%)default
: utilizza la modalità di default del viewerlayout
single
: mostra una pagina per voltacontinuous
: mostra le pagine in modo continuotwo
: mostra due pagine su due colonnedefault
: utilizza la modalità di default del viewerdefault
.
SetDrawColor(int r [, int g, int b])
r
g
e b
sono dati, indica il componente rosso; altrimenti indica il livello di grigio.
Valori tra 0 e 255.
g
b
SetFillColor(int r [, int g, int b])
r
g
e b
sono dati, indica il componente rosso; altrimenti indica il livello di grigio.
Valori tra 0 e 255.
g
b
SetFont(string family [, string style [, float size]])
FPDF_FONTPATH
(se la costante esiste)include()
FPDF_FONTPATH
:
define('FPDF_FONTPATH','/home/www/font');
require('fpdf.php');
family
Courier
(fixed-width)Helvetica
o Arial
(sinonimi; sans serif)Times
(serif)Symbol
(symbolic)ZapfDingbats
(symbolic)style
B
: grassettoI
: corsivoU
: sottolineatoSymbol
e ZapfDingbats
.
size
// Times normale 12
$pdf->SetFont('Times');
// Arial grassetto 14
$pdf->SetFont('Arial','B',14);
// Rimuove il grassetto
$pdf->SetFont('');
// Times grassetto, corsivo e sottolineato 14
$pdf->SetFont('Times','BIU');
SetFontSize(float size)
size
SetKeywords(string keywords [, boolean isUTF8])
keywords
isUTF8
false
) o UTF-8 (true
).false
.
SetLeftMargin(float margin)
margin
SetLineWidth(float width)
width
SetLink(int link [, float y [, int page]])
link
y
-1
indica la posizione corrente.
Il valore di default è 0
(inizio pagina).
page
-1
indica la pagina corrente. E' il valore di default.
SetMargins(float left, float top [, float right])
left
top
right
SetRightMargin(float margin)
margin
SetSubject(string subject [, boolean isUTF8])
subject
isUTF8
false
) o UTF-8 (true
).false
.
SetTextColor(int r [, int g, int b])
r
g
e b
sono dati, indica il componente rosso; altrimenti indica il livello di grigio.
Valori tra 0 e 255.
g
b
SetTitle(string title [, boolean isUTF8])
title
isUTF8
false
) o UTF-8 (true
).false
.
SetTopMargin(float margin)
margin
SetX(float x)
x
SetXY(float x, float y)
x
y
SetY(float y [, boolean resetX])
y
resetX
true
.
Text(float x, float y, string txt)
x
y
txt
Write(float h, string txt [, mixed link])
h
txt
link
// Inizia con un font normale
$pdf->SetFont('Arial','',14);
$pdf->Write(5,'Visit ');
// Quindi inserisce un link blu sottolineato
$pdf->SetTextColor(0,0,255);
$pdf->SetFont('','U');
$pdf->Write(5,'www.fpdf.org','http://www.fpdf.org');
__construct([string orientation [, string unit [, mixed size]]])
orientation
P
o Portrait
L
o Landscape
P
.
unit
pt
: puntimm
: millimetricm
: centimetriin
: pollicimm
.
size
A3
A4
A5
Letter
Legal
unit
).
A4
.
$pdf = new FPDF('P','mm',array(100,150));
1. Esattamente qual'è la licenza di FPDF? Ci sono limitazioni all'utilizzo?
FPDF è rilasciata con licenza permissiva: non vi sono restrizioni di utilizzo. Puoi incorporarla liberamente nelle tue applicazioni (commerciali o meno), con o senza modifiche.2. Quando tento di generare un PDF, ricevo il seguente messaggio di errore: "Some data has already been output, can't send PDF file".
Non devi inviare al browser nient'altro che il solo PDF: non HTML, nessuno spazio o ritorno di carrello. Un caso comune consiste nell'avere uno spazio bianco indesiderato alla fine dello script di un file incluso.ob_end_clean();
3. I caratteri accentati vengono sostituiti da strani caratteri come é.
Non utilizzare la codifica UTF-8. I font standard FPDF utilizzano ISO-8859-1 o windows-1252. Vi è la possibilità di effettuare una conversione verso ISO-8859-1 tramite utf8_decode():$str = utf8_decode($str);
$str = iconv('UTF-8', 'windows-1252', $str);
4. Tento di inserire il simbolo dell'Euro ma non funziona.
I font standard hanno il simbolo dell'euro alla posizione 128. Puoi definire per convenienza una costante come questa:define('EURO', chr(128));
5. Provo a visualizzare una variabile nel metodo Header, ma non viene stampato nulla.
Devi utilizzare la parola chiaveglobal
per accedere alle variabili globali, per esempio:
function Header()
{
global $title;
$this->SetFont('Arial', 'B', 15);
$this->Cell(0, 10, $title, 1, 1, 'C');
}
function Header()
{
$this->SetFont('Arial', 'B', 15);
$this->Cell(0, 10, $this->title, 1, 1, 'C');
}
$pdf->title = 'My title';
6. Ho definito i metodi Header e Footer nella mia classe PDF ma non appare nulla.
Devi creare un oggetto dalla classe PDF, non FPDF:$pdf = new PDF();
7. Non riesco a far funzionare le interruzioni di linea. Inserisco i \n nella stringa stampata da MultiCell ma non funziona.
Devi chiudere la stringa tra virgolette, non tra apici singoli.8. Per generare il PDF uso jQuery, ma non viene mostrato.
Non usare una richiesta AJAX per recuperare il file PDF.9. Ho disegnato un frame di dimensioni molto precise, ma quando viene stampato noto alcune differenze.
Per rispettare le dimensioni, scegli "Nessuno" nel settaggio della scala di stampa al posto di "Restringi all'area di stampa" nel box di dialogo della stampa.10. Vorrei utilizzare l'intera superficie della pagina, ma quando stampo restano sempre alcuni margini. Come posso eliminarli?
Tutte le stampanti hanno dei margini fisici (diversi a seconda del modello), ed è quindi impossibile rimuoverli e stampare su tutta la superficie della carta.11. Come posso impostare uno sfondo nel mio PDF?
Per un'immagine, effettua una chiamata a Image() all'interno del metodo Header(), prima di ogni altro output. Per impostare un colore di sfondo usa Rect().12. Come posso impostare una specifica intestazione o un piede nella prima pagina?
Semplicemente, testa il numero di pagina:function Header()
{
if($this->PageNo()==1)
{
//First page
...
}
else
{
//Other pages
...
}
}
13. Vorrei poter utilizzare estensioni rese disponibili tramite diversi script. Come posso combinarle?
Utilizza un'ereditarietà a catena. Se hai due classi, diciamo A in a.php:require('fpdf.php');
class A extends FPDF
{
...
}
require('fpdf.php');
class B extends FPDF
{
...
}
require('a.php');
class B extends A
{
...
}
require('b.php');
class PDF extends B
{
...
}
$pdf = new PDF();
14. Come posso aprire il PDF in una nuova scheda?
Basta fare quanto si fa per una pagina HTML o per altro: aggiungere un target = "_blank" al proprio link o form.15. Come posso inviare il PDF tramite email?
Come ogni altro file, ma una via semplice è utilizzare PHPMailer e il suo sistema di allegati in-memory:$mail = new PHPMailer();
...
$doc = $pdf->Output('S');
$mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
$mail->Send();
16. Qual'è il limite delle dimensioni dei file che posso generare con FPDF?
Non c'è un limite particolare. Ci sono comunque alcune restrizioni:17. Posso modificare un PDF con FPDF?
Grazie all'estensione FPDI, è possibile importare pagine da un documento PDF preesistente. Poi, puoi aggiungere ad esse altro contenuto.18. Vorrei creare un motore di ricerca in PHP e indicizzare i file PDF. Posso farlo utilizzando FPDF?
No, ma esiste una utility scritta in C e rilasciata sotto licenza GPL, pdftotext, che consente di estrarre il contenuto testuale da un PDF. E' fornita col il pacchetto Xpdf.19. Posso convertire una pagina HTML in PDF con FPDF?
Non pagine del "mondo reale". No, ma esiste una utility scritta in C e rilasciata sotto licenza GPL, HTMLDOC, che permette di farlo ottenendo buoni risultati.20. Posso concatenare files PDF con FPDF?
Non direttamente, ma è possibile utilizzare FPDI per raggiungere tale obiettivo. Esistono anche alcuni tools liberi a linea di comando: pdftk e mbtPdfAsm.<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
$pdf = new FPDF('P','mm','A4');
L
), altri tipi di formati (come A3
e A5
) e unità di misura (pt
, cm
, in
).
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World !',1);
$pdf->Cell(60,10,'Powered by FPDF.',0,1,'C');
<?php
require('fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('logo.png',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,'Title',1,0,'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();
?>
{nb}
che è sostituito nel testo quando il documento è concluso
(a condizione di chiamare prima AliasNbPages()).
<?php
require('fpdf.php');
class PDF extends FPDF
{
function Header()
{
global $title;
// Arial bold 15
$this->SetFont('Arial','B',15);
// Calculate width of title and position
$w = $this->GetStringWidth($title)+6;
$this->SetX((210-$w)/2);
// Colors of frame, background and text
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
// Thickness of frame (1 mm)
$this->SetLineWidth(1);
// Title
$this->Cell($w,9,$title,1,1,'C',true);
// Line break
$this->Ln(10);
}
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Text color in gray
$this->SetTextColor(128);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function ChapterTitle($num, $label)
{
// Arial 12
$this->SetFont('Arial','',12);
// Background color
$this->SetFillColor(200,220,255);
// Title
$this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
// Line break
$this->Ln(4);
}
function ChapterBody($file)
{
// Read text file
$txt = file_get_contents($file);
// Times 12
$this->SetFont('Times','',12);
// Output justified text
$this->MultiCell(0,5,$txt);
// Line break
$this->Ln();
// Mention in italics
$this->SetFont('','I');
$this->Cell(0,5,'(end of excerpt)');
}
function PrintChapter($num, $title, $file)
{
$this->AddPage();
$this->ChapterTitle($num,$title);
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
$pdf->Output();
?>
true
indica che lo sfondo deve essere riempito).
<?php
require('fpdf.php');
class PDF extends FPDF
{
protected $col = 0; // Current column
protected $y0; // Ordinate of column start
function Header()
{
// Page header
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);
// Save ordinate
$this->y0 = $this->GetY();
}
function Footer()
{
// Page footer
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->SetTextColor(128);
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function SetCol($col)
{
// Set position at a given column
$this->col = $col;
$x = 10+$col*65;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
// Method accepting or not automatic page break
if($this->col<2)
{
// Go to next column
$this->SetCol($this->col+1);
// Set ordinate to top
$this->SetY($this->y0);
// Keep on page
return false;
}
else
{
// Go back to first column
$this->SetCol(0);
// Page break
return true;
}
}
function ChapterTitle($num, $label)
{
// Title
$this->SetFont('Arial','',12);
$this->SetFillColor(200,220,255);
$this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
$this->Ln(4);
// Save ordinate
$this->y0 = $this->GetY();
}
function ChapterBody($file)
{
// Read text file
$txt = file_get_contents($file);
// Font
$this->SetFont('Times','',12);
// Output text in a 6 cm width column
$this->MultiCell(60,5,$txt);
$this->Ln();
// Mention
$this->SetFont('','I');
$this->Cell(0,5,'(end of excerpt)');
// Go back to first column
$this->SetCol(0);
}
function PrintChapter($num, $title, $file)
{
// Add chapter
$this->AddPage();
$this->ChapterTitle($num,$title);
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
$pdf->Output();
?>
<?php
require('fpdf.php');
class PDF extends FPDF
{
// Load data
function LoadData($file)
{
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';',trim($line));
return $data;
}
// Simple table
function BasicTable($header, $data)
{
// Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
// Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
// Better table
function ImprovedTable($header, $data)
{
// Column widths
$w = array(40, 35, 40, 45);
// Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
// Data
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();
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
// Colored table
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = array(40, 35, 40, 45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$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;
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf = new PDF();
// Column headings
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');
// Data loading
$data = $pdf->LoadData('countries.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 metodo Cell() che specifica quali lati della cella debbano essere
disegnati. Qui vogliamo il lato sinistro (L
) e destro (R
). Rimane il
problema della linea orizzontale per finire la tabella. Ci sono due possibilità: sia
controllare quando si arriva all'ultima riga del ciclo, in questo caso utilizzare LRB
per il parametro border
or, come è stato fatto qui, aggiungere la riga quando finisce il ciclo.
<?php
require('fpdf.php');
class PDF extends FPDF
{
protected $B = 0;
protected $I = 0;
protected $U = 0;
protected $HREF = '';
function WriteHTML($html)
{
// HTML parser
$html = str_replace("\n",' ',$html);
$a = preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($a as $i=>$e)
{
if($i%2==0)
{
// Text
if($this->HREF)
$this->PutLink($this->HREF,$e);
else
$this->Write(5,$e);
}
else
{
// Tag
if($e[0]=='/')
$this->CloseTag(strtoupper(substr($e,1)));
else
{
// Extract attributes
$a2 = explode(' ',$e);
$tag = strtoupper(array_shift($a2));
$attr = array();
foreach($a2 as $v)
{
if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
$attr[strtoupper($a3[1])] = $a3[2];
}
$this->OpenTag($tag,$attr);
}
}
}
}
function OpenTag($tag, $attr)
{
// Opening tag
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,true);
if($tag=='A')
$this->HREF = $attr['HREF'];
if($tag=='BR')
$this->Ln(5);
}
function CloseTag($tag)
{
// Closing tag
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,false);
if($tag=='A')
$this->HREF = '';
}
function SetStyle($tag, $enable)
{
// Modify style and select corresponding font
$this->$tag += ($enable ? 1 : -1);
$style = '';
foreach(array('B', 'I', 'U') as $s)
{
if($this->$s>0)
$style .= $s;
}
$this->SetFont('',$style);
}
function PutLink($URL, $txt)
{
// Put a hyperlink
$this->SetTextColor(0,0,255);
$this->SetStyle('U',true);
$this->Write(5,$txt,$URL);
$this->SetStyle('U',false);
$this->SetTextColor(0);
}
}
$html = 'You can now easily print text mixing different styles: <b>bold</b>, <i>italic</i>,
<u>underlined</u>, or <b><i><u>all at once</u></i></b>!<br><br>You can also insert links on
text, such as <a href="http://www.fpdf.org">www.fpdf.org</a>, or on an image: click on the logo.';
$pdf = new PDF();
// First page
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->Write(5,"To find out what's new in this tutorial, click ");
$pdf->SetFont('','U');
$link = $pdf->AddLink();
$pdf->Write(5,'here',$link);
$pdf->SetFont('');
// Second page
$pdf->AddPage();
$pdf->SetLink($link);
$pdf->Image('logo.png',10,12,30,0,'','http://www.fpdf.org');
$pdf->SetLeftMargin(45);
$pdf->SetFontSize(14);
$pdf->WriteHTML($html);
$pdf->Output();
?>
MakeFont(string fontfile [, string enc [, boolean embed [, boolean subset]]])
fontfile
Percorso del file .ttf, .otf or .pfb.
enc
Nome della codifica in uso. Predefinito: cp1252
.
embed
Se incorporare il font o meno. Predefinito: true
.
subset
Se inserire il sottoinsieme del font o meno. Predefinito: true
.
$file
del file .php di conseguenza.
<?php
require('makefont/makefont.php');
MakeFont('C:\\Windows\\Fonts\\comic.ttf','cp1252');
?>
$pdf->AddFont('Comic','','comic.php');
$pdf->AddFont('Comic','B','comicbd.php');
<?php
require('makefont/makefont.php');
MakeFont('CevicheOne-Regular.ttf','cp1252');
?>
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddFont('CevicheOne','','CevicheOne-Regular.php');
$pdf->AddPage();
$pdf->SetFont('CevicheOne','',45);
$pdf->Write(10,'Enjoy new fonts with FPDF!');
$pdf->Output();
?>