I need to put underlined text into Pdf file with Zend Framework. Is it possible somehow?
Try this method $page->setLineDashingPattern(array(3, 2, 3, 4), 1.6)
. I don't try this but maybe helps.
Here's what I'm using.. the -2 is just arbitrary, but it looks fine.
Oh, and this is part of my method to center text but you could pull it out.
/**
* Draw text aligned to the right
* @param Zend_Pdf_Page $page page
* @param string $text - text to draw
* @param float $right - right position
* @param float $top - top position
* @param boolean $underline - whether or not to underline the text
*/
public function drawTextCentered(Zend_Pdf_Page $page, $text, $top, $underline = false)
{
$textWidth = $this->getTextWidth($text, $page->getFont(), $page->getFontSize());
$left = ($page->getWidth() - $textWidth) / 2;
$page->drawText($text, $left, $top);
if ($underline) {
$page->drawLine($left, $top-2, $left+$textWidth, $top-2);
}
}
/**
* Return the width of generated string in points
* @param string $text text
* @param Zend_Pdf_Resource_Font $font font
* @param integer $fontSize font size
*
* @return float text width
*/
public function getTextWidth($text, Zend_Pdf_Resource_Font $font, $fontSize)
{
$text = iconv('', 'UTF-16BE', $text);
$chars = array();
for ($i = 0; $i < strlen($text); $i++) {
$chars[] = (ord($text[$i++]) << 8) | ord($text[$i]);
}
$glyphs = $font->glyphNumbersForCharacters($chars);
$widths = $font->widthsForGlyphs($glyphs);
return (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.