I need to use Zend_Pdf to make an invoice.
How I can calulate width of a "text" with a specific font and size ?
I've tried the method behind
(http://devzone.zend.com/article/2525-Zend_Pdf-tutorial)
I've extend Zend_Pdf class and append the method ...
I've tried to call the method as this :
$this->widthForStringUsingFontSize($cell, Zend_Pdf_Font::FONT_HELVETICA, 8);
It works but seems that returns incorrect value because when I draw a vertical line
to this same position, text and line are aligned !
public 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;
}
I've got the same problem when I try to
right align data. As returned with is incorrect I'm not be abble to align my cells !
Any ideas ?
Regards
没有评论:
发表评论