codice:
<?php
// file fpdf_js.php
class PDF_Javascript extends FPDF {
var $javascript;
var $n_js;
function IncludeJS($script) {
$this->javascript=$script;
}
function _putjavascript() {
$this->_newobj();
$this->n_js=$this->n;
$this->_out('<<');
$this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R ]');
$this->_out('>>');
$this->_out('endobj');
$this->_newobj();
$this->_out('<<');
$this->_out('/S /JavaScript');
$this->_out('/JS '.$this->_textstring($this->javascript));
$this->_out('>>');
$this->_out('endobj');
}
function _putresources() {
parent::_putresources();
if (!empty($this->javascript)) {
$this->_putjavascript();
}
}
function _putcatalog() {
parent::_putcatalog();
if (isset($this->javascript)) {
$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
}
}
}
?>
<?php
// file classe_stampa.php
class PDF_classe extends PDF_Javascript
{
function Row($data)
{
$this->SetFillColor(232,232,232);
$this->SetFont('Arial','',8);
//Numero
$this->SetY(2);
$this->Cell(50,0,'Numero Protocollo',0,0,'L',0);
$this->Cell(1,0,$data[Numero],0,0,'R',0);
//Data
$this->SetY(5);
$this->Cell(0,0,'Data',0,0,'L',0);
$this->Cell(0,0,$data[data_prot],0,0,'R',0);
//Cognome
$this->SetY(8);
$this->Cell(0,0,'Cognome',0,0,'L',0);
$this->Cell(0,0,$data[Cognome],0,0,'R',0);
//Nome
$this->SetY(11);
$this->Cell(0,0,'Nome',0,0,'L',0);
$this->Cell(0,0,$data[Nome],0,0,'R',0);
//Oggetto
$this->SetY(14);
$this->Cell(0,0,'Oggetto',0,0,'L',0);
$this->Cell(0,0,$data[Oggetto],0,0,'R',0);
}
function Table($query)
{
//errore query
$res=mysql_query($query) or die('Error: '.mysql_error()."
Query: $query");
while($row=mysql_fetch_array($res))
{
$this->AddPage();
$this->Row($row);
//$this->AddPage();
}
}
}
?>
<?php
define('FPDF_FONTPATH','font/');
include ("config.php");
require('fpdf/fpdf.php');
require('fpdf_js.php');
require('classe_stampa.php');
class PDF_AutoPrint extends PDF_classe
{
function AutoPrint($dialog=false)
{
//Embed some JavaScript to show the print dialog or start printing immediately
$param=($dialog ? 'true' : 'false');
$script="print($param);";
$this->IncludeJS($script);
}
}
$pdf=new PDF_AutoPrint();
$pdf->AliasNbPages();
$pdf->Open();
$pdf->Table("SELECT * ,DATE_FORMAT(Data,'%d/%m/%Y') as data_prot FROM protocollo");
//Launch the print dialog
$pdf->AutoPrint(true);
$pdf->Output();
?>