Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá pessoal,
estou utilizando o FPDF para a geração de relatório.
Como é a primeira vez que utilizo ele, estou precisando de ajuda para a seguinte situação:
Tenho uma célula que tem um tamanho definido. Acontece é que a variável que o relatório irá mostrar dentro da célula na maioria das vezes é maior que o tamanho máximo (wight) definido. Ex:
CÉLULA:
==============================
| hfah jhladj lkadfh jklfhak hklhkjl hadf | jf klajkfl jdaklj fkladj jkflaj kadf jkla .
| |
==============================
Está acontecendo isto.
Minha dúvida é: Como posso definir uma quebra de linha automática?
(Para que o texto se ajuste conforme a célula)
Marlon, obrigado pela a ajuda.
Me ajudou em relação a outras dúvidas. No entanto, ao que se refere a inserir um texto dentro de uma célula, como o exemplo acima no tópico, não estou conseguindo fazer ele respeitar o limite da célula.
Demorei para responder porque fiz diversos testes e tentei de diversas formas. E não consegui.
Eu utilizo uma extensão, para tabelas onde existe largura fixa das colunas.
<?php
class pdf extends fpdf
{
var $widths;
var $aligns;
var $height;
function SetHeight($h)
{
//Set the height of each line
$this->height=$h;
}
function SetWidths($w)
{
//Set the array of column widths
$this->widths=$w;
}
function SetAligns($a)
{
//Set the array of column alignments
$this->aligns=$a;
}
function Row($data)
{
//Calculate the height of the row
$nb=0;
$mh = 5;
$mh = max($mh, $this->height);
for($i=0;$i< count($data);$i++)
$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
$h=$mh*$nb;
//Issue a page break first if needed
$this->CheckPageBreak($h);
//Draw the cells of the row
for($i=0;$i< count($data);$i++)
{
$w=$this->widths[$i];
$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Draw the border
$this->Rect($x,$y,$w,$h);
//Print the text
$this->MultiCell($w,$mh,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function CheckPageBreak($h)
{
//If the height h would cause an overflow, add a new page immediately
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function NbLines($w,$txt)
{
//Computes the number of lines a MultiCell of width w will take
$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;
}
}
?>$pdf->SetWidths(array(10, 45, 40, 50, 35));
$pdf->SetHeight(6);
$pdf->SetAligns(array('C', 'C', 'C', 'J', 'L'));
$pdf->Row(array('ID', 'USUARIO', 'CPF/CNPJ', 'OBS', 'PERMISSOES'));
$pdf->Row(array($id, $nome_usuario, $documento, $observacoes, $perm));
Não esquecer de alterar para $pdf = new pdf(....);, porque você extende a classe principal
Acho que você pode utilizar o exemplo desse link (http://fpdf.de/downloads/addons/49/).