我有这个。
for($i=0; $i < $longArreglo; $i++) {
$this->Cell($w[0],6, $final_array[$i][0],'LR',0,'L', $fill);
$this->Cell($w[1],6, $final_array[$i][2],'LR',0,'C', $fill);
$this->Cell($w[2],6, $final_array[$i][3],'LR',0,'L', $fill);
$this->Cell($w[3],6, $final_array[$i][5],'LR',0,'C', $fill);
$this->Cell($w[4],6, $final_array[$i][6],'LR',0,'C', $fill);
$this->Cell($w[5],6, $final_array[$i][12],'LR',0,'C', $fill);
$this->Cell($w[6],6, $final_array[$i][13],'LR',0,'C', $fill);
$this->Cell($w[7],6, $final_array[$i][14],'LR',0,'C', $fill);
$this->Cell($w[8],6, $final_array[$i][15],'LR',0,'C', $fill);
$this->Cell($w[9],6, $final_array[$i][16],'LR',0,'C', $fill);
$this->Cell($w[10],6, $final_array[$i][17],'LR',0,'C', $fill);
$this->Cell($w[11],6, $final_array[$i][18],'LR',0,'C', $fill);
$this->Cell($w[12],6, $final_array[$i][19],'LR',0,'C', $fill);
$this->Cell($w[13],6, $final_array[$i][20],'LR',0,'C', $fill);
$this->Ln();
}
在这里:$this->Cell($w[2],6, $final_array[$i][3],'LR',0,'L', $fill);
是一个人名,单元格的宽度是15,如果名称最大于单元格,它会这样做:
我需要细胞不合并。
答案 0 :(得分:0)
所以,例子应该是:
// width - width of cell
// text to be put into cell
// pdf - pdf object of fpdf
// fill - how to fill cell?
function putField($width,$text,$pdf,$fill){
$textwidth = $pdf->getstringwidth($text);
while($textwidth>$width){ // loop until textwidth is shorter than cell width
$text=substr($text,0,-1); // strip last char
$textwidth = $pdf->getstringwidth($text); // read text width again
}
$pdf->Cell($width,6, $text,'LR',0,'L', $fill); // put the cell
}
for($i=0; $i < $longArreglo; $i++) {
putField($w[0],$final_array[$i][0],$this,$fill);
}
答案 1 :(得分:0)
这篇文章可能很旧,但是我在互联网上找不到其他解决方案。我修改了雨果(Hugo)的帖子,希望有一天对某人有所帮助。为了方便使用,我在fpdf类中创建了一个新方法。
function pdfText($cellWidth, $text, $pdf){
$textWidth = $pdf->getstringwidth($text);
while($textWidth > $cellWidth -1){
$text = substr($text,0,-1);
$textWidth = $pdf->getstringwidth($text);
}
return $text;
}
require_once('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint esse quia repellat cupiditate excepturi exercitationem asperiores eligendi iusto. Blanditiis sequi suscipit assumenda quibusdam aliquid quas eligendi soluta ab fugit ad.';
$pdf->setFont('Arial', '', 10);
$cellWidth = 180;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,6,$text,1,1,'L',0);
$pdf->setFont('Arial', '', 12);
$cellWidth = 160;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,7,$text,1,1,'L',0);
$pdf->setFont('Arial', '', 14);
$cellWidth = 140;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,8,$text,1,1,'L',0);
$pdf->setFont('Arial', '', 16);
$cellWidth = 120;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,9,$text,1,1,'L',0);
$pdf->Output('I');