Zend PDF hat keine eingebaute Möglichkeit die Breite eines Strings zu bestimmen. Man kann sich aber trotzdem behelfen...
Wer gerne die Breite eines Strings für die Benutzung mit Zend PDF haben möchte, kann gerne die statische Methode stringWidth benutzen.
Anmerkung: Die Methode stringWidth liefert nur einen Nährungswert, welcher aber in der Regel ausreichend ist.
Download Code!
class Zend_PDF_Helper {
public static function stringWidth
($text, Zend_Pdf_Resource_Font
$font, $font_size) { $drawing_text = iconv ( '', 'UTF-16BE', $text ); for($i = 0; $i < strlen ( $drawing_text ); $i ++) { $characters [] = (ord ( $drawing_text [$i ++] ) << <img src
="/templates/default/img/emoticons/cool.png" alt
="8-)" style
="display: inline; vertical-align: bottom;" class="emoticon" /> | ord ( $drawing_text [$i] ); }
$glyphs = $font->glyphNumbersForCharacters ( $characters );
$widths = $font->widthsForGlyphs ( $glyphs );
$text_width = (array_sum ( $widths ) / $font->getUnitsPerEm ()) * $font_size; return $text_width;
}
}