0

我知道有 drawImage 函数来绘制图像。我想要的只是将我的图像打印到 PDF 的最后一页,在底部。我怎样才能做到这一点?这是功能:

page->drawImage($image, $imageTopLeft, $imageTop, $imageBottomRight, $imageBottom);

在此处添加坐标将在给定位置的每个页面上绘制它,不是吗?

谢谢!

4

1 回答 1

4

如果您像这样创建 PDF 和页面:

$pdf = new Zend_Pdf();

$page1 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
// set content to this page
$pdf->pages[] = $page1;

$page2 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
// set content to this page
$pdf->pages[] = $page2;

// and so on ...

你可以这样做:

//Get your last page with $pdf->pages[count($pdf->pages[])-1]

$pdf->pages[count($pdf->pages[])-1]->drawImage($image, $imageTopLeft, $imageTop, $imageBottomRight, $imageBottom);

如果要查找文本宽度以调整其他元素,可以使用此功能:

    /**
     * Calculate width of given text
     * 
     * @param String $text 
     * @param Zend_Pdf_Resource_Font $font
     * @param int $font_size
     * @return int 
     */
    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;
    }

而不是你打电话给:

$this->getTextWidth('some dinamyc text ', $font, $font_size);
于 2012-02-21T16:14:46.860 回答