Zend_Pdf和模板

时间:2011-06-20 22:36:25

标签: zend-framework pdf pdf-generation zend-pdf

我在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)相比的许多功能但仍然必须有一些方法可以为所有页​​面制作基本的页眉/页脚吗?

1 个答案:

答案 0 :(得分:0)

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

$page1 = clone $template;

或只是

$pdf->pages[] = clone $pdf->pages[0];
相关问题