Hey Willie,

nice to see Zend_Pdf progressing.

I use it to pre fill an insurance form. Here ist the template:

http://www.rosa-kautionsversicherung.de/kautionsversicherung-premium-antrag/antrag.pdf

It is quite a beast. Many fields. It is a lot of work to find all the coordinates of the fields, so I create a little tool the creates a grid on top of a PDF.

grid.php
+++
require_once 'Zend/Pdf.php';

$file = $argv[1];
$pagenumber = isset($argv[2]) ? intval($argv[2]) : 1;
$dest = str_replace('.pdf', '', $file) . "-grid-$pagenumber.pdf";

$pdf = Zend_Pdf::load($file);

$page = $pdf->pages[$pagenumber-1];
$width  = $page->getWidth();
$height = $page->getHeight();

$style = new Zend_Pdf_Style();
$style->setFillColor(new Zend_Pdf_Color_Html('#aaaaaa'));
$style->setLineColor(new Zend_Pdf_Color_Html('#a73e3a'));
$style->setLineWidth(.2);
$style->setLineDashingPattern(array(1, 2, 1, 2), .1);
$style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 4);

$page->setStyle($style);

for ($i = 20; $i < $height - 20; $i+=10)
{
  $page->drawLine(20, $i, $width-20, $i);
  $page->drawText($i, 11, $i);
  $page->drawText($i, $width-20, $i);
}

for ($i = 20; $i < $width - 20; $i+=10)
{
  $page->drawLine($i, 20, $i, $height-20);
  $page->drawText($i, $i, 15);
  $page->drawText($i, $i, $height-20);
}

puts("$file ($pagenumber) -> $dest\nw: $width, h: $height");
$pdf->save($dest);
+++

But still, it is a *lot* of work (takes hours) to find all coordinates of the above mentioned PDF. This is how I fill out the forms after all fields are validated:

+++
# just an excerpt
  $pdffelder[3] = array(
    'Grundbesitz/Immobilien ja' => array('X', 345, 780),
    'Grundbesitz/Immobilien nein' => array('X', 373, 780),
    'Vermietungfirma ja' => array('X', 345, 760),
    'Vermietungfirma nein' => array('X', 373, 760),
'Teile Anlagevermögen' => array($f['Teile_des_Anlagevermoegens_der_Gesellschaft'], 305, 741),
    'Art Immobilien' => array($f['Art_der_Grundstuecke_und_Gebaeude'], 195, 
721),
'Wert Immobilien' => array($f['Wert_der_Grundstuecke_und_Gebaeude'], 200, 701),
# it goes on like this, and later

$style = new Zend_Pdf_Style();
$style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER), 8);

foreach ($pdffelder as $pagenumber => $pdfdata)
{
  $page = $pdf->pages[$pagenumber];
  $page->setStyle($style);
  foreach ($pdfdata as $k => $v)
  {
    $page->drawText($v[0], $v[1], $v[2], 'UTF-8');
  }
}

$pdf->save('antrag.pdf');
+++

So, what would be a killer feature for me, would be the ability two define fields and coordinates in Acrobat. ID those and just write text to those IDs. I believe other packages are able to do this. This would also get rid of another problem of mine: line breaks or multiline fields and page breaks etc.

Thanks a lot for your work so far.

-sasa ebach

Reply via email to