Gorilla3D の最悪のケースのアルゴリズムを使用するのではなく、幅を正確に計算する方法があります。
http://devzone.zend.com/article/2525-Zend_Pdf-tutorial#comments-2535からこのコードを試してください
アプリケーションで右揃えのテキストのオフセットを計算するために使用しましたが、機能します
/**
* Returns the total width in points of the string using the specified font and
* size.
*
* This is not the most efficient way to perform this calculation. I'm
* concentrating optimization efforts on the upcoming layout manager class.
* Similar calculations exist inside the layout manager class, but widths are
* generally calculated only after determining line fragments.
*
* @link http://devzone.zend.com/article/2525-Zend_Pdf-tutorial#comments-2535
* @param string $string
* @param Zend_Pdf_Resource_Font $font
* @param float $fontSize Font size in points
* @return float
*/
function widthForStringUsingFontSize($string, $font, $fontSize)
{
$drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $string);
$characters = array();
for ($i = 0; $i < strlen($drawingString); $i++) {
$characters[] = (ord($drawingString[$i++]) << 8 ) | ord($drawingString[$i]);
}
$glyphs = $font->glyphNumbersForCharacters($characters);
$widths = $font->widthsForGlyphs($glyphs);
$stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
return $stringWidth;
}
パフォーマンスに関しては、これをスクリプトで集中的に使用したことはありませんが、遅いことは想像できます。可能であれば、PDFをディスクに書き込むことをお勧めします。これにより、繰り返しビューが非常に高速になり、可能な場合はデータをキャッシュ/ハードコーディングできます。