简体   繁体   English

FPDF A4纸不打印最后一行

[英]FPDF A4 Paper not print last row

I'm trying to make printing rows on A4 paper, no matter number of rows. 我正在尝试在A4纸上打印行,无论行数是多少。 It's important that rows occupy the entire length of A4 paper (297mm). 行占据A4纸的整个长度(297毫米)很重要。

Example: 例:
So, if I want 4 rows this means that the entire length of the paper A4 is divided by 4 and print so that four rows equally occupy the entire A4 paper. 因此,如果我要4行,这意味着将纸张A4的整个长度除以4并进行打印,以便四行相等地占据整个A4纸张。 The problem is that the last row is printed on different paper. 问题是最后一行打印在不同的纸张上。
I don't know why? 不知道为什么
Does anyone have advice how to solve problem? 有人建议如何解决问题吗?

Here is my php code: 这是我的PHP代码:

<?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 is 2cm bottom margin): 您需要在添加页面之前设置自动分页符(默认为2cm底边距):

$pdf->SetAutoPageBreak(TRUE, 0);

http://www.fpdf.org/en/doc/setautopagebreak.htm http://www.fpdf.org/en/doc/setautopagebreak.htm

And it will be better if you change the code a 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();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM