2012-09-26 147 views
5

FPDFには、クライアント名を入れる必要がある幅が176mmのセルがあります。問題は、クライアント名が常に固定幅に調整されないことです。セルのフォントサイズをセル幅に合わせて自動調整する方法はありますか?フォントサイズを調整するFPDF

これは私が今持っているコードです:

$pdf->Cell(116, 7, utf8_decode($row_or[ 'client_name' ]), 0, 0, 'L'); 

私はTCPDFが自動ストレッチを設定する方法を持っていることを知っているが、私はFPDFのためのいずれかを発見していません。私はコードでそれをしなければならないのですか?

答えて

6

まあ、それは私が何をしたか、された文字列を受け取り、milimetersにその幅を返すGetStringWidthと呼ばれる機能があることが判明し、そう:

/* I know that the font size starts with 11, so i set a variable at this size */ 
$x = 11; // Will hold the font size 
/* I will cycle decreasing the font size until it's width is lower than the max width */ 
while($pdf->GetStringWidth(utf8_decode($row_or[ 'client_name' ])) > 116){ 
    $x--; // Decrease the variable which holds the font size 
    $pdf->SetFont('Trebuchet', 'B', $x); // Set the new font size 
} 
/* Output the string at the required font size */ 
$pdf->Cell(116, 7, utf8_decode($row_or[ 'client_name' ])), 0, 0, 'L'); 
/* Return the font size to itś original */ 
$pdf->SetFont('Trebuchet', 'B', 11); 
0

減少がためにあまりにもポイントの分画することができより細かい列の調整: $ x- = 0.1; $ x--の代わりに ;

関連する問題