我知道有繪製圖像的drawImage函數。我想要的只是將圖像打印到底部的PDF最後一頁。我怎樣才能做到這一點?這是函數:使用Zend PDF在最後一頁上繪製圖像?
page->drawImage($image, $imageTopLeft, $imageTop, $imageBottomRight, $imageBottom);
添加在這裏的座標將繪製它的每一頁上的指定位置,慣於呢?
謝謝!
我知道有繪製圖像的drawImage函數。我想要的只是將圖像打印到底部的PDF最後一頁。我怎樣才能做到這一點?這是函數:使用Zend PDF在最後一頁上繪製圖像?
page->drawImage($image, $imageTopLeft, $imageTop, $imageBottomRight, $imageBottom);
添加在這裏的座標將繪製它的每一頁上的指定位置,慣於呢?
謝謝!
如果您創建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);
看起來不錯,有沒有辦法在沒有任何x/y值的情況下繪製它?我必須將它繪製在PDF上的另一個元素下面。元素始終不在同一位置。 – EOB 2012-02-22 10:07:33
不,據我所知。比你必須設置x/y關於另一個元素x/y值的動態。 – tasmaniski 2012-02-22 10:32:48
我該怎麼做?另一個元素是不會改變的文本。 – EOB 2012-02-22 10:49:32
你是如何創建pdf的? – tasmaniski 2012-02-21 16:15:13