i'm trying make printing rows on a4 paper, no matter number of rows. it's important rows occupy entire length of a4 paper (297mm).
example:
so, if want 4 rows means entire length of paper a4 divided 4 , print 4 rows equally occupy entire a4 paper. problem last row printed on different paper.
don't know why?
have advice how solve problem?
here php code:
<?php require('fpdf/fpdf.php'); class pdf extends fpdf { } $pdf = new pdf('p', 'mm', array(210, 297)); $pdf->setfont('arial', '', 8); $pdf->addpage(); $widhtmm = 210; $pdf->setmargins(0, 0, 0, 0); $heightmm = 295; $pdf->setxy(0, 0); $margintop = 0; $rows = 7; $testo = ''; for($i = 0; $i < $rows; $i++) { $heightmm = 297 / $rows; if ($i == 0) { $margintop = 0; } else { $margintop += $heightmm; } $pdf->setxy(0, $margintop); $pdf->cell($widhtmm, $heightmm, $heightmm, 'lrtb', 0, 'l', 0); $pdf->ln(); } $pdf->output(); ?>
you need set auto page break before add page (by default 2cm bottom margin):
$pdf->setautopagebreak(true, 0); http://www.fpdf.org/en/doc/setautopagebreak.htm
and better if change code little bit:
$heightmm = 297 / $rows; for($i = 0; $i < $rows; $i++) { $margintop = $i*$heightmm; $pdf->setxy(0, $margintop); $pdf->cell($widhtmm, $heightmm, $heightmm, 'lrtb', 0, 'l', 0); $pdf->ln(); }
Comments
Post a Comment