cs_sidalilo
Messages postés108Date d'inscriptionmardi 28 février 2006StatutMembreDernière intervention 9 juillet 2013
-
6 juin 2010 à 17:35
mgmbow
Messages postés1Date d'inscriptionvendredi 25 avril 2008StatutMembreDernière intervention 5 août 2011
-
5 août 2011 à 14:08
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');
}
//----------------------------------------------------------------------------
// 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->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
mgmbow
Messages postés1Date d'inscriptionvendredi 25 avril 2008StatutMembreDernière intervention 5 août 2011 5 août 2011 à 14:08
Salu cessez avec et prenez ceci:
Ce fichier sqppelle mc_table.php
require('fpdf.php');
class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;
function SetWidths($w)
{
//Tableau des largeurs de colonnes
$this->widths=$w;
}
function SetAligns($a)
{
//Tableau des alignements de colonnes
$this->aligns=$a;
}
function Row($data)
{
//Calcule la hauteur de la ligne
$nb=0;
for($i=0;$i<count($data);$i++)
$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
$h=5*$nb;
//Effectue un saut de page si nécessaire
$this->CheckPageBreak($h);
//Dessine les cellules
for($i=0;$i<count($data);$i++)
{
$w=$this->widths[$i];
$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
//Sauve la position courante
$x=$this->GetX();
$y=$this->GetY();
//Dessine le cadre
$this->Rect($x,$y,$w,$h);
//Imprime le texte
$this->MultiCell($w,5,$data[$i],0,$a);
//Repositionne à droite
$this->SetXY($x+$w,$y);
}
//Va à la ligne
$this->Ln($h);
}
function CheckPageBreak($h)
{
//Si la hauteur h provoque un débordement, saut de page manuel
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function NbLines($w,$txt)
{
//Calcule le nombre de lignes qu'occupe un MultiCell de largeur w
$cw=&$this->CurrentFont['cw'];
if($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 and $s[$nb-1]=="\n")
$nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
$c=$s[$i];
if($c=="\n")
{
$i++;
$sep=-1;
$j=$i;
$l=0;
$nl++;
continue;
}
if($c==' ')
$sep=$i;
$l+=$cw[$c];
if($l>$wmax)
{
if($sep==-1)
{
if($i==$j)
$i++;
}
else
$i=$sep+1;
$sep=-1;
$j=$i;
$l=0;
$nl++;
}
else
$i++;
}
return $nl;
}
}
?>
Ce fichier peut sappeler imprime.php par exemple:
Et suivant ta base de données et tes tables tu peut modifier la requete
require('mc_table.php');
include ("connexion_base.php");
// En-tête
$sql = mysql_query("select date, libelle_journal, D_etude, NomClient from j_journaux order by date");
$done = mysql_fetch_array($sql);