Project

General

Profile

Add page number,

Added by Alonso Uribe almost 11 years ago

How I can add the page number on each page in a table?

when I add the page number, the second page is no displayed.

example: add_page.png

how adding a high limit to jump to the next page?

after the second page I do not respect the footer margin

example: footer.png

thank you very much


Replies (5)

RE: Add page number, - Added by Andrei Bintintan almost 11 years ago

The table uses the margin values to calculate the "available" space on the page:
$oPdf->SetMargins(20, 20, 20);

There is no other option to add a "height limit" to the table, except SetMargins, so is very important to be correct.

So, if you have a HIGH footer, then set it accordingly.

To limit the number of rows on a page but triggering a $oTable->addPageBreak(), this will break the table to the next page.

I don't know why the page number is not displayed on your second page, please post your header code.

RE: Add page number, - Added by Alonso Uribe almost 11 years ago

I don't use the page number in the header or footer, The page number is in the table.

The function $oTable->addPageBreak() is before closing the table? (the function doesn't work)

This function $oPdf->SetMargins(); only uses the margins left, top, right and above but bottom?

This is the code to generate the table:

$columns = array(
array('TEXT' => 'COLUMN 1'),
array('TEXT' => 'COLUMN 2'),
array('TEXT' => 'SUBCOLUMN 1'),
array('TEXT' => 'SUBCOLUMN 2'),
array('TEXT' => 'SUBCOLUMN 3'),
array('TEXT' => 'SUBCOLUMN 4'),
array('TEXT' => 'COLUMN 4')
);

$this->pdf = new PDF('L', 'mm', 'Legal');

$this->pdf->Open();
$this->pdf->SetAutoPageBreak(true, 70);
$this->pdf->AddPage();
$this->pdf->AliasNbPages();

$this->pdf->Cell(285);
$this->pdf->Cell(0, 4, "Page {$this->pdf->PageNo()} / {nb}", 0, 'L');
$this->pdf->Ln(10);

$oTable = new TfpdfTable($this->pdf);
$oTable->initialize(array(40, 40, 60, 25, 30, 30, 60));

$oTable->addHeader($columns);
$oTable->addHeader($columns);
$oTable->addHeader($columns);

$oTable->setHeaderProperty(0, 'ROWSPAN', 3);
$oTable->setHeaderProperty(1, 'ROWSPAN', 3);
$oTable->setHeaderProperty(2, 'TEXT', 'COLUMN 3');
$oTable->setHeaderProperty(2, 'ROWSPAN', 2);
$oTable->setHeaderProperty(2, 'COLSPAN', 4);
$oTable->setHeaderProperty(6, 'ROWSPAN', 3);

$aData = array();

foreach($aData as $row)
{
$addRow = array();
$addRow[0]['TEXT'] = ' ';
$addRow[1]['TEXT'] = ' ';
$addRow[2]['TEXT'] = ' ';
$addRow[3]['TEXT'] = ' ';
$addRow[4]['TEXT'] = ' ';
$addRow[5]['TEXT'] = ' ';
$addRow[6]['TEXT'] = ' ';
$oTable->addRow($addRow);
}
$oTable->close();

RE: Add page number, - Added by Alonso Uribe almost 11 years ago

I sent the complete code and a demonstration to solve the problem faster.

demo:
http://alonsouribe.com/tfpdf

code:
http://alonsouribe.com/tfpdf/demo.zip

RE: Add page number, - Added by Andrei Bintintan almost 11 years ago

See the attached file.

  1. The pages has to be part of the header, how did you expected it to work from the index file!?

    public function Header ()
    {
    $this->SetY(10);
    $imagen = 'images/logo.png';
    $this->Image($imagen, 35, 10, 18);
    $this->SetFont('Arial', 'B', 13);
    $this->Cell(0, 5, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 0, 0, 'C');
    $this->Cell(-25, 15, 'XXXXXXXXXXXX', 0, 0, 'R');
    $this->Ln(5);
    $this->Cell(0, 5, 'XXXXXXXXXXXXXXXXXXXX', 0, 0, 'C');
    $this->SetFont('Arial', '', 13);
    $this->Cell(-25, 15, 'XXXXXXXXXXXX', 0, 0, 'R');
    $this->Ln(9);
    $this->SetFont('Arial', 'B', 13);
    $this->Cell(0, 5, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 0, 0, 'C');
    $this->Ln(9);
    $this->SetFont('Arial', 'B', 12);
    $this->Cell(0, 5, 'XXXXXXXXXXXXXXXXXXXXXXXXXX', 0, 0, 'C');
    $this->Ln(15);
    $this->setX(280);
    $this->Cell(0, 4, "Page {$this->PageNo()} / {nb}", 0, 'L');
    $this->Ln(10);
    }

  2. Set your document margins properly, this is quite important for the table.

    $oPdf->Open();
    $oPdf->SetAutoPageBreak(true, 70);
    $oPdf->AddPage();
    $oPdf->AliasNbPages();
    $oPdf->SetMargins(20, 60, 20);

..correct the 60 to the correct header height.

RE: Add page number, - Added by Andrei Bintintan almost 11 years ago

See attached file:

demo.zip demo.zip 19.3 KB
    (1-5/5)