【问题标题】:Zend_PDF text formattingZend_PDF 文本格式化
【发布时间】:2009-08-18 17:49:50
【问题描述】:

我在我的项目中使用 Zend 框架。我的问题是如何使用 Zend_PDF 将像 "helloworld" 之类的 html 文本转换为 PDF 文本?

谢谢。

【问题讨论】:

    标签: php text formatting zend-pdf


    【解决方案1】:

    我认为没有像 html2pdf 这样的自动转换功能。您可以像这样设置字体:

    $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');
    

    【讨论】:

    • 嗯,可以,但是有一个新问题。我有不同的单词间距。当单词的长度不同时,它们之间的间距也不同,因为字体不是等宽的。我该如何解决这个问题?
    • 别介意我在网上找到了解决办法 public function getTextWidth($text, Zend_Pdf_Resource_Font $font, $font_size) { $drawing_text = iconv('', 'UTF-16BE', $text ); $字符 = 数组();对于 ($i = 0; $i glyphNumbersForCharacters($characters); $widths = $font->widthsForGlyphs($glyphs); $text_width = (array_sum($widths) / $font->getUnitsPerEm()) * $font_size;返回 $text_width; }
    猜你喜欢
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多