Codice PHP:
<?php
date_default_timezone_set('Europe/Rome');
require_once(LIBS . 'tcpdf/config/lang/ita.php');
require_once(LIBS . 'tcpdf/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES.'logo_example.jpg';
$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
// Title
$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
Class pdf extends MYPDF{
private $pdf;
private function initfile() {
$pdffile = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdffile->SetCreator(PDF_CREATOR);
$pdffile->SetAuthor('Nicola Asuni');
$pdffile->SetTitle('TCPDF Example 001');
$pdffile->SetSubject('TCPDF Tutorial');
$pdffile->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdffile->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdffile->setFooterData($tc=array(0,64,0), $lc=array(0,64,128));
// set header and footer fonts
$pdffile->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdffile->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdffile->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdffile->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdffile->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdffile->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdffile->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdffile->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdffile->setLanguageArray($l);
// ---------------------------------------------------------
// set default font subsetting mode
$pdffile->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdffile->SetFont('dejavusans', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdffile->AddPage();
// set text shadow effect
$pdffile->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
return $pdffile;
}
public function crea() {
$this->pdf=$this->initfile();
$this->pdf->AddPage();
// set text shadow effect
$this->pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
// Set some content to print
$html = <<<EOD
<style>
h1 {
color: navy;
font-family: times;
font-size: 24pt;
text-decoration: underline;
text-align:center;
}
p {
color: #003300;
font-family: helvetica;
font-size: 12pt;
}
</style>
<hr>
<h1>Prima Pagina PDF</h1>
Questa è la prima pagina HTML</p>
EOD;
// Print text using writeHTMLCell()
//$pdf->writeHTMLCell($w=0, $h=0, $x='10', $y='', $html, $border='T', $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);
$this->pdf->writeHTML($html, $ln = true, $fill = false, $reseth = false, $cell = false, $align = '');
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$this->pdf->Output('example_001.pdf', 'I');
}
}
?>
L'Editor mi segnala un errore in questa riga