Я сделал нечто подобное, используя PHP-библиотеку FILE_PDF.Он принимает данные POST в виде dates[]
или hours[]
и заполняет ими таблицу. Вот мой код, он не идеален, но может дать вам начало
$tasks = array("dates","descriptions","hours","minutes");
foreach($tasks as $name)
{
$$name = explode("\n",$_POST[$name]);
}
for ($i=0;$i<count($descriptions);$i++)
{
$data[]=array("dates"=>$dates[$i],"descriptions"=>$descriptions[$i],"hours"=>$hours[$i],"minutes"=>$minutes[$i]);
}
$p = &File_PDF::factory('P','mm','A4');
$p->open();
$p->setMargins(25, 25);
$p->addPage('P');
$p->setFont('arial', '', 24);
$p->cell(0, 9, "Invoice", 0, 1, 'C');
$p->setFont('arial', '', 14);
$p->write(6,date("F j, Y"));
$p->newLine();
$p->write(6,"Invoice #DIM-09-10-001");
$p->newLine();
$p->write(6,"Invoice for X");
$p->newLine();
$p->newLine();
$p->setFont('arial', '', 12);
$p->write(10, 'Work performed @ hourly rate of $20.00');
$p->newLine();
$p->newLine();
$widths = array(23,90,15,25);
$header = array("Date","Task","","Time");
foreach($header as $num=>$col)
$p->Cell($widths[$num],7,$col,"B");
$p->newLine();
foreach($data as $row)
{
$i=0;
foreach($row as $name=>$col)
{
$p->Cell($widths[$i],10,$col,0);
$i++;
}
$p->newLine();
}
$table_footer = array(array("","Total Time",'8 hours @ $20/hour'),array("","Total Fees Due",'$160'));
$widths = array(80,35,40);
$borders = array(array(0,"T","T"));
foreach($table_footer as $rownum=>$row)
{
foreach($row as $num=>$col)
$p->Cell($widths[$num],10,$col,$borders[$rownum][$num]);
$p->newLine();
}
$p->write(10,"Please make check payable to ");
$p->setFontStyle("B");
$p->write(10,"David Mihal");
$p->newLine();
$p->newLine();
$p->setFontStyle("I");
$p->write(4,"All invoices are due and payable within 30 days. Thank you for your prompt attention to this invoice and for your continued business.");
$p->close();
$p->output('invoice.pdf',true);