fPDFでPDFを生成しています。
MultiCell内の長いテキストを取り消し線で消す必要があります。テキストは左右に揃えられており、これがおそらく問題の原因です。
これが私のコードです:
//get the starting x and y of the cell to strikeout
$strikeout_y_start = $pdf->GetY();
$strikeout_x = $pdf->getX();
$strikeText = "Some text with no New Lines (\n), which is wrapped automaticly, cause it is very very very very very very very very very very long long long long long long long long long long long long long long long long long long"
//draw the text
$pdf->MultiCell(180, 4, $strikeText);
//get the y end of cell
$strikeout_y_end = $pdf->GetY();
$strikeout_y = $strikeout_y_start+2;
$strikeCount = 0;
for ($strikeout_y; $strikeout_y < $strikeout_y_end - 4; $strikeout_y+=4) {
$strikeCount++;
//strike out the full width of all lines but last one - works OK
$pdf->Line($strikeout_x, $strikeout_y, $strikeout_x + 180, $strikeout_y);
}
//this works, but gives incorrect results
$width = $pdf->GetStringWidth($strikeText);
$width = $width - $strikeCount*180;
//the line below will strike out some text, but not all the letters of last line
$pdf->line($strikeout_x, $strikeout_y, $strikeout_x+$width, $strikeout_y);
問題は、マルチセル内のテキストが正当化される(そして正当化される必要がある)ため、前の行のspacecがGetStringWidthが想定するよりも広いため、GetStringWidthがこのテキストの全幅を過小評価することです。
その結果、最後の行は、たとえば70%でストロークされ、その末尾の一部の文字はストロークされません。
マルチセルの最後の行の幅を計算する方法はありますか?