我想加載一個現有的pdf文件,並填充數據庫信息。加載文件和一切工作,除了寫入數據到加載頁面。它不會將文本寫入加載的頁面。如果我添加一個新頁面並使用foreach將繪圖應用於所有頁面,則所有添加的頁面都會被寫入,除了已加載的頁面。下面是我使用的代碼:用Zend Framework在一個加載的pdf文件上繪製文本
$pdf = Zend_Pdf::load('./documents/agreements/_root/gegevens.pdf'); // Load pdf
$pdf->pages = array_reverse($pdf->pages); // reverse pages
$pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); // Add a page (A4)
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Set font
foreach($pdf->pages as $page) // Apply settings+text to every page (total of 2)
{
$page->setFont($font, 36);
$page->setAlpha(0.25);
$page->drawText('LALALALALALALA', 62, 260, 'UTF-8');
}
$pdf->save('./documents/agreements/Gegevens_'.$this->school_id.'.pdf'); // Save file
不幸的是,沒有工作。 在PDF中有設置導致頁面不可寫入的可能性? – 2010-06-15 07:38:20
是的,如果PDF是密碼或寫保護是可能的,那麼你將無法寫入它。上述方法可以在我的非受保護的pdf發票模板上正確使用 – Mark 2010-06-15 14:58:57