/** * Calculate the width of a string: * in case of using alignment parameter in drawText * @param string $text * @param Zend_Pdf_Font $font * @param float $fontSize * @return float */ public function widthForStringUsingFontSize($text, $font, $fontSize) { $drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $text); $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; }