Project

General

Profile

Problem with PdfTable and PageBreak

Added by Marco Steindl over 9 years ago

Hello,

I have problems with the PageBreak at the PdfTable, if there is a bigger page-header (which I need on each pdf page).

For example:
if I don't reset the "SetY" in the header function (like in the code examples: "$this->SetY($this->tMargin)" ), it depends on the header's size (or the "Ln" which is used there), if the oTable do a right PageBreak or not.

Please see my code example and the pdf outputs - with a higher Ln in the header (e.g. "Ln(30)") the table will overwrite the footer to the end of the current page (but not at the first page, the wrong page break starts at the second page...)

Thanks in advance!

Best regards
Marco


Replies (6)

RE: Problem with PdfTable and PageBreak - Added by Andrei Bintintan over 9 years ago

Hi Marco,

There are 2 things you have to make sure:

  1. your page margins are correct

$oPdf->SetAutoPageBreak ( true, 20 );
$oPdf->SetMargins ( 20, 20, 20 );

  1. Your header functions respect these margins and at the exit of the header function the Y is set to the correct value.

If you need more space in the footer and header set the correct values there: 30, 40 ...

The table calculates it's height based on these values. This will solve your issue.

RE: Problem with PdfTable and PageBreak - Added by Marco Steindl over 9 years ago

Hello again,

as I found out, the problem probably is in the /classes/Pdf/Table.php function "_cachePaginate" (about line ~1150)

If I overwrite the "$iLeftHeight = $iPageHeight;" (near the end of this function), the output will be better.

As a workaround I currently use this:

  • at my own "Header()" function at the end: save the Y coord in a new variable:
    "$this->header_pos = $this->y;"

  • at the top of the "_cachePaginate" function, add after:
    "$iPageHeight = $this->PageHeight();"
    a second var:
    "$iPageHeightOrig = $iPageHeight - $this->oPdf->header_pos + $this->oPdf->tMargin;"
    (it's similar to the "$iLeftHeight" definition but without the GetY() and with the "header_pos" header-Y-coord. )

  • at the end of the "_cachePaginate" function, replace:
    "$iLeftHeight = $iPageHeight;"
    with
    "$iLeftHeight = $iPageHeightOrig;"

I've tested it and as I could see, it should work more or less as a workaround...

If you have a better solution or a bugfix, please let me know (maybe there is a better way to solve this bug in the "tfpdf" class in the Cell function by using the "InHeader" variable to save the headers Y-coord. or something else...)

Thanks in advance!

Best regards
Marco

RE: Problem with PdfTable and PageBreak - Added by Marco Steindl over 9 years ago

Hi,

sorry, I saw your answer after sending my workaround...

Yes, of course, the margins I've set should be right (because if I set a higher top-margin, also my header will moved down)

Am I right?: if I set at the end of the my "Header()" the Y (using setY or Ln), the table should work correctly?
Yes, it starts at the right place, but the table will be written over the footer (which has it's own/correct "SetY(-15)") to the end of each current page and will be snipped there (all pages, but not the first page - the first page works correctly)

If I'm right, there is a wrong calculation of the pdf-header when a new page will be added (maybe at each following new page the pdf-header (not the table-header) size will be ignored?)

Thanks & best regards
Marco

RE: Problem with PdfTable and PageBreak - Added by Andrei Bintintan over 9 years ago

I think the mistake is that you're using wrongly the Ln function. It's not doing the same thing as SetY. Ln adds a line of the specified size.

Example:
$pdf->Ln(30) adds 30 units to the current Y and it's NOT setting the Y to 30.

I've attached your corrected example, there are 2 code changes:

  1. in ex1.php: $oPdf->SetMargins ( 20, 30, 20 );

Your top margin is 30

  1. in header function:

use setY instead of Ln

//$this->Ln(30);
$this->SetY(30);

I hope this clarifies things.

The page height is calculated correctly. The table works the following way:

  1. on the first Page Height is the current Y - rest of the space to the footer.
  2. the next pages the Page Height is the full available height (top margin - bottom margin difference).

RE: Problem with PdfTable and PageBreak - Added by Marco Steindl over 9 years ago

Hi,

thanks for your answer.

Ok, seems that I went wrong ;)

I thought the margin is for the whole pdf document (space around) and below of the top-margin the header will be placed and reduces the rest of the page height...

So is it right, that if my header is about Y=60, the top-margin should also be set so 60? (or 55, 65 or something like this depending on the style etc. ...)

So if I always want the same top-margin for the table, I could set a variable to 60 and use it at the end of the header by "setY" and at the "SetMargins" function?

Thanks!

    (1-6/6)