Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Zend PDF在最后一页上绘制图像?_Php_Zend Framework_Pdf Generation_Zend Pdf - Fatal编程技术网

Php 使用Zend PDF在最后一页上绘制图像?

Php 使用Zend PDF在最后一页上绘制图像?,php,zend-framework,pdf-generation,zend-pdf,Php,Zend Framework,Pdf Generation,Zend Pdf,我知道有drawImage函数来绘制图像。我只想把我的图片打印到PDF的最后一页,在底部。我该怎么做?这就是功能: page->drawImage($image, $imageTopLeft, $imageTop, $imageBottomRight, $imageBottom); /** * Calculate width of given text * * @param String $text * @param Zend_Pdf_

我知道有drawImage函数来绘制图像。我只想把我的图片打印到PDF的最后一页,在底部。我该怎么做?这就是功能:

page->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;
    }
在这里添加坐标将在给定位置的每页上绘制坐标,不是吗


谢谢

如果您创建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);

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

page->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;
    }

如果您创建的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);

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

page->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;
    }

看起来不错,有没有办法不使用任何x/y值来绘制它?我必须把它画在PDF的另一个元素下面。元素不总是在同一个位置。不,我知道。然后,您必须针对另一个元素的x/y值设置x/y动态。我将如何做到这一点?另一个元素是不会改变的文本。这将返回我67。。。我现在该怎么办?用它来画图像?如果是,怎么做?:)谢谢然后,您的徽标的x位置将是:x-position-of-text+67+右填充…看起来不错,有没有办法在没有任何x/y值的情况下绘制它?我必须把它画在PDF的另一个元素下面。元素不总是在同一个位置。不,我知道。然后,您必须针对另一个元素的x/y值设置x/y动态。我将如何做到这一点?另一个元素是不会改变的文本。这将返回我67。。。我现在该怎么办?用它来画图像?如果是,怎么做?:)谢谢然后您的徽标的x位置将是:文本的x位置+67+右填充。。。。。