2

我在 Zend_Pdf 中为我的 pdf 文档创建模板时遇到问题。我已按照http://framework.zend.com/manual/en/zend.pdf.pages.html提供的指南进行操作,但它似乎不起作用,因为除了第一的。

这是我的代码示例:(注意;MTP 常数只是从 mm 到点的重新计算)

//Create pdf object
$pdf = new Zend_Pdf();

//Create the first page
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);

/*HEADER*/
//insert logo at the top
$logo = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../document_root/images/logotype.png');
$page->drawImage($logo, 22*MTP,274*MTP, 62*MTP, 289*MTP); 

/*FOOTER*/
$footerStyle->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10);
$page->setStyle($footerStyle);
$page->drawText('Footer text', 33*MTP, 20*MTP, 'ISO-8859-1');

//save the page to pdf->pages
$pdf->pages[0] = $page;

//save the page as a template
$template = $pdf->pages[0];

//create the next page from template
$page1 = new Zend_Pdf_Page($template);

//save the next page to pdf->pages
$pdf->pages[] = $page1;

我是否完全误解了这个“模板函数”在 Zend_Pdf 中是如何工作的?我知道 Zend_Pdf 与一些外部 pdf 生成器(如 FPDF)相比缺乏相当多的功能,但仍然必须有某种方法为所有页面制作基本的页眉/页脚,对吗?

4

1 回答 1

0

尝试使用clone将页面作为参数传递给新页面。

$page1 = clone $template;

或者干脆

$pdf->pages[] = clone $pdf->pages[0];
于 2011-06-21T16:14:40.137 回答