2009年6月26日星期五

RE: [fw-mvc] zend pdf - align text at right

I found the following function on the internet after some searching. It works wonderfully!

protected function word_width($string, $font, $fontSize) {
$drawingString = iconv('', 'UTF-16BE', $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;
}

-----Original Message-----
From: Remy Damour [mailto:remy.damour@gmail.com]
Sent: Friday, June 26, 2009 6:30 PM
To: Zend Framework MVC
Subject: [fw-mvc] zend pdf - align text at right

Hi,

I'm currently giving a shot at pdf generation through Zend_Pdf, and
first of all, thanks for the job done, it's great and quite easy to
use.

I have a question though, is it possible to know the size of
text-string to be drawn (Zend_Pdf_Page::drawText())?
I need it to be able to align my text on the right (if anyone has a
better idea, do not hesitate!)

Regards,
Remy


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4193 (20090626) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4193 (20090626) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

没有评论: