views:

32

answers:

2

Hello,

I'm trying to load a existing pdf file, and fill this with database information. Loading the file and everything is working, except for writing data to the loaded page. It doesn't write text to the loaded page. If I add a new page en use a foreach to apply drawing to all pages, all added pages are written, except for the loaded one. Below is the code I'm using:

$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
A: 

Try the following:

$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
Mark
Unfortunatly that didn't work.Is it a poosibility that there are settings in the pdf that are causing the page unwrittable?
Rick de Graaf
yes it is possible if the pdf is password or write protected then you won't be able to write to it. The method above works correctly for me on my non-protected pdf invoice templates
Mark
+1  A: 

I solved the problem: I created a new pdf file with different settings. Creating the pdf with the following settings (I use Acrobat PDFmaker Office COM Addin for word) did the trick. I guess the code was working after all, the pdf itself was causing the problems.

In word select save as PDF Select the 'Quick and simple PDF' format

Change the settings in 'Adobe PDF conversion options':

Enable -> Convert document information
Enable -> Make PDF/A Compliant
Disable -> Create bookmarks from
Disable -> Convert Comments

Note: This regards saving a file as PDF in word. Other office applications aren't tested.

Rick de Graaf