bonjour
j'ai essayé d'exporter une recap vers pdf par le fpdf mais j'ai un champ qui contient un long text et affiché avec decalage dans la hauteur
merci bien de vous m'aidez pour faire un text dans une cellule sans decalage dans la hauteur
voila le script:
<?php
session_start();
require('fpdf.php');
class PDF extends FPDF
{
//Chargement des données
function LoadData($file)
{
//Lecture des lignes du fichier
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Tableau amélioré
function ImprovedTable($header,$data)
{
//Largeurs des colonnes
$w=array(15,20,20,6,15,50,20,4,4,4,4,4,4,4,4,4);
//En-tête
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Données
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,$row[2],'LR');
$this->Cell($w[3],6,$row[3],'LR');
$this->Cell($w[4],6,$row[4],'LR');
$this->Cell($w[5],6,$row[5],'LR');
$this->Cell($w[6],6,$row[6],'LR');
$this->Cell($w[7],6,$row[7],'LR');
$this->Cell($w[8],6,$row[8],'LR');
$this->Cell($w[9],6,$row[9],'LR');
$this->Cell($w[10],6,$row[10],'LR');
$this->Cell($w[11],6,$row[11],'LR');
$this->Cell($w[12],6,$row[12],'LR');
$this->Cell($w[13],6,$row[13],'LR');
$this->Cell($w[14],6,$row[14],'LR');
$this->Cell($w[15],6,$row[15],'LR');
$this->Ln();
}
//Trait de terminaison
$this->Cell(array_sum($w),0,'','T');
}
function WordWrap(&$text, $maxwidth)
{
$text = trim($text);
if ($text==='')
return 0;
$space = $this->GetStringWidth(' ');
$lines = explode("\n", $text);
$text = '';
$count = 0;
foreach ($lines as $line)
{
$words = preg_split('/ +/', $line);
$width = 0;
foreach ($words as $word)
{
$wordwidth = $this->GetStringWidth($word);
if ($wordwidth > $maxwidth)
{
// Word is too long, we cut it
for($i=0; $i<strlen($word); $i++)
{
$wordwidth = $this->GetStringWidth(substr($word, $i, 1));
if($width + $wordwidth <= $maxwidth)
{
$width += $wordwidth;
$text .= substr($word, $i, 1);
}
else
{
$width = $wordwidth;
$text = rtrim($text)."\n".substr($word, $i, 1);
$count++;
}
}
}
elseif($width + $wordwidth <= $maxwidth)
{
$width += $wordwidth + $space;
$text .= $word.' ';
}
else
{
$width = $wordwidth + $space;
$text = rtrim($text)."\n".$word.' ';
$count++;
}
}
$text = rtrim($text)."\n";
$count++;
}
$text = rtrim($text);
return $count;
}
//----------------------------------------------------------------------------
// MULTI CELL
// @in $w = largeur de la cellule (occupe toute la ligne si $w == 0)
// @in $h = hauteur de la ligne (et non pas de la cellule multi-lignes !!)
// @in $txt = texte à insérer
// @in $border = spécification de bordure (0,1,'L','T','R','B')
// @in $align = spécification d'alignement ('L', 'R', 'C', 'J')
// @in $fill = spécification de remplissage (0,1)
// @in $cursorPos = placement du curseur après traitement (0=à droite, 1=saut de ligne)
//----------------------------------------------------------------------------
function multiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = 0, $cursorPos = 1) {
// NB : ces contorsions sont rendues nécessaires par le fait que dans la classe de base,
// SetY() a comme effet de bord de replacer le curseur à gauche...
if( $cursorPos == 0 ) {
$y = $this->GetY();
$x = $this->GetX() + $w;
}
parent::MultiCell($w, $h, $txt, $border, $align, $fill);
if( $cursorPos == 0 ) {
$this->SetY($y);
$this->SetX($x);
}
}
function Header()
{
$this->SetFont('Arial','',14);
$this->multiCell('300','6',"{$_SESSION['nonrapport']} Répertoire des documents Qualités et Techniques du Service Métrologie",'0','L','0','0');
//$this->Write(6, "Répertoire des documents Qualités et Techniques du Service Métrologie");
$this->Ln();
$this->Ln();
$this->SetFont('Arial','',8);
$this->multiCell('25','3','Lieu d\'Affectation','0','L','0','0');
$this->multiCell('30','3','Type de procedure','0','L','0','0');
$this->multiCell('40','3','Domaine','0','L','0','0');
$this->multiCell('8','3','ind','0','L','0','0');
$this->multiCell('24','3','Date d\'application','0','L','0','0');
$this->multiCell('30','3','Ident','0','L','0','0');
$this->multiCell('80','3','Intitulé du document','0','L','0','0');
$this->multiCell('5','3','R Q','0','L','0','0');
$this->multiCell('5','3','M S','0','L','0','0');
$this->multiCell('5','3','R S','0','L','0','0');
$this->multiCell('5','3','U O','0','L','0','0');
$this->multiCell('5','3','S','0','L','0','0');
$this->multiCell('5','3','C','0','L','0','0');
$this->multiCell('5','3','F','0','L','0','0');
$this->multiCell('5','3','M','0','L','0','0');
$this->multiCell('5','3','L','0','L','0','1');
$this->SetDrawColor(0,80,180);
$this->SetLineWidth(1);
$this->Line(5, 30, 293, 30);
$this->multiCell('5','6',"",'0','L','0','1');
//$this->Cell(190,10,"",0,1,'C');
//$this->Ln();
}
//Pied de page
function Footer()
{
$this->SetTextColor(220,50,50);
$this->SetDrawColor(0,80,180);
//$this->Ln();
//$this->Ln();
//$this->Ln();
//$this->Ln();
$this->Sety(-17);
$this->Line(00, 190, 300, 190);
$this->SetFont('Arial','',8);
$this->multiCell('300','6','RQ: responsable qualité ; MS: Métrologie sur site ; RS: Responsable de service ;
UO: Responsable Unité Opérationel ; S: Secrétaire ; C: Commercial ; F: Correspondant Formation ; M: Métrologue ; L: Laboratoire','0','C','0','0');
$this->SetTextColor(0,0,0);
$this->Cell(0,5,'Page '.$this->PageNo().' sur {nb}',0,0,'R');
}
}
//$pdf=new PDF();
$pdf=new PDF('L','mm','A4');
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',8);
mysql_connect("localhost","root","mysql");
mysql_select_db("documentaire");
$req = mysql_query("SELECT * FROM repertoire WHERE lieu='{$_SESSION['lieu']}'");
$pdf->multiCell('5','1',"",'0','J','0','1');
while($result = mysql_fetch_array($req))
{
//$pdf->multiCell('5','1',"",'0','J','0','1');
//$lieu=$result['lieu'];
//$nb=$pdf->WordWrap($result['lieu'], 25);
$pdf->multiCell('25','3',$result['lieu'],'0','L','0','0');
//$type=$result['type'];
//$nb=$pdf->WordWrap($result['type'], 25);
$pdf->multiCell('30','3',$result['type'],'0','L','0','0');
//$dom=$result['domaine'];
//$nb=$pdf->WordWrap($result['domaine'], 45);
$pdf->multiCell('40','3',$result['domaine'],'0','L','0','0');
//$ind=$result['ind'];
//$nb=$pdf->WordWrap($result['ind'], 25);
$pdf->multiCell('8','3',$result['ind'],'0','L','0','0');
//$ap=$result['application'];
//$nb=$pdf->WordWrap($result['application'], 23);
$pdf->multiCell('24','3',$result['application'],'0','L','0','0');
//$rap=$result['rapport'];
//$nb=$pdf->WordWrap($result['rapport'], 25);
$pdf->multiCell('30','3',$result['rapport'],'0','L','0','0');
//$int=$result['intitule'];
//$pdf->SetFont('Arial','',10);
//$nb=$pdf->WordWrap($result['intitule'], 50);
$pdf->multiCell('80','3',$result['intitule'],'0','L','0','0');
//$pdf->SetFont('Arial','',10);
//$rq=$result['rq'];
//$nb=$pdf->WordWrap($result['rq'], 7);
$pdf->multiCell('5','3',$result['rq'],'0','L','0','0');
//$ms=$result['ms'];
//$nb=$pdf->WordWrap($result['ms'], 7);
$pdf->multiCell('5','3',$result['ms'],'0','L','0','0');
//$rs=$result['rs'];
//$nb=$pdf->WordWrap($result['rs'], 7);
$pdf->multiCell('5','3',$result['rs'],'0','L','0','0');
//$uo=$result['uo'];
//$nb=$pdf->WordWrap($result['uo'], 7);
$pdf->multiCell('5','3',$result['uo'],'0','L','0','0');
//$s=$result['s'];
//$nb=$pdf->WordWrap($result['s'], 7);
$pdf->multiCell('5','3',$result['s'],'0','L','0','0');
//$c=$result['c'];
//$nb=$pdf->WordWrap($result['c'], 7);
$pdf->multiCell('5','3',$result['c'],'0','L','0','0');
//$f=$result['f'];
//$nb=$pdf->WordWrap($result['f'], 7);
$pdf->multiCell('5','3',$result['f'],'0','L','0','0');
//$m=$result['m'];
//$nb=$pdf->WordWrap($result['m'], 7);
$pdf->multiCell('5','3',$result['m'],'0','L','0','0');
//$l=$result['l'];
//$nb=$pdf->WordWrap($result['l'], 7);
$pdf->multiCell('5','3',$result['l'],'0','L','0','1');
$pdf->multiCell('5','6',"",'0','J','0','1');
//$pdf->Cell(190,10,"",0,1,'C');
//$pdf->Ln();
}
$pdf->Output();
?>
voiola un exemple:
$hauteur=6;
$nb="1";
$long=$pdf->GetStringWidth($observ) ;
if($long>250)
{
$nb=250/$long;
}
//$nb= ceil (250 / $long) ;
//$pdf->Cell($centrage);
$nb=$pdf->WordWrap($observ, 45);
$pdf->multiCell('30',$hauteur/$nb,"longtext",'1','L','0',$sl);
est ce que c'est juste??
merci pour votre attention