views:

287

answers:

1

Hi, I use Zend Framework for my project. And my question is how can I convert html text like "helloworld" into PDF text to be the same using Zend_PDF ?

Thx.

+1  A: 

Hi , i think there is no automatic convert function like html2pdf. You can set the Font like this :

$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER_BOLD);
$pdfPage->setFont($font, 36) // font and size
        ->drawText('hello', 72, 720, 'UTF-8')
        ->drawText('world', 72, 650, 'UTF-8');
ArneRie
Hmm , it works ,but there is a new problem. I have different spacing between words. When words have different length they also have different spacing between them because font is not monospaced. How can I workaround this ?
Vasilii
Don't mind I found the solution in the internet public function getTextWidth($text, Zend_Pdf_Resource_Font $font, $font_size) { $drawing_text = iconv('', 'UTF-16BE', $text); $characters = array(); for ($i = 0; $i < strlen($drawing_text); $i++) { $characters[] = (ord($drawing_text[$i++]) << 8) | ord ($drawing_text[$i]); } $glyphs = $font->glyphNumbersForCharacters($characters); $widths = $font->widthsForGlyphs($glyphs); $text_width = (array_sum($widths) / $font->getUnitsPerEm()) * $font_size; return $text_width; }
Vasilii