使用Zend Framework在加载的pdf文件上绘制文本

时间:2010-06-14 09:20:20

标签: zend-framework pdf

我正在尝试加载现有的pdf文件,并将其填入数据库信息。加载文件,一切正常,除了将数据写入加载的页面。它不会将文本写入已加载的页面。如果我添加新页面并使用foreach将绘图应用于所有页面,则会写入所有添加的页面,但加载的页面除外。以下是我正在使用的代码:

$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

3 个答案:

答案 0 :(得分:1)

我解决了问题:我创建了一个具有不同设置的新pdf文件。使用以下设置创建pdf(我使用Acrobat PDFmaker Office COM Addin for word)就可以了。我猜这段代码毕竟是正常的,pdf本身就是造成问题的原因。

在单词中选择另存为PDF 选择“快速简单的PDF”格式

更改“Adobe PDF转换选项”中的设置:

启用 - >转换文档信息
启用 - >使PDF / A符合要求 禁用 - >从中创建书签 禁用 - >转换评论

注意:这涉及将文件保存为单词PDF。其他办公室应用程序未经过测试。

答案 1 :(得分:0)

尝试以下方法:

$pdf = Zend_Pdf::load('./documents/agreements/_root/gegevens.pdf'); // Load pdf
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Set font
foreach($pdf->pages as $pid => $page) // Apply settings+text to every page (total of 2)
{
    $myPage = new Zend_Pdf_Page($page);
    $myPage->setFont($font, 36);
    $myPage->setAlpha(0.25);
    $myPage->drawText('LALALALALALALA', 62, 260, 'UTF-8');
    $pdf->pages[$pid] = $page;
}
$pdf->save('./documents/agreements/Gegevens_'.$this->school_id.'.pdf'); // Save file

答案 2 :(得分:0)

尝试这个。

$pdf->pages[i]->drawText('LALALALALALALA', 62, 260, 'UTF-8');