Skip to content

Commit 32dd474

Browse files
authored
Merge pull request #89 from stkruse/bug_fix
Take top page margin, page header and table header into account for page breaks in long tables
2 parents 9e3fed4 + dd9ba8c commit 32dd474

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/pdfxml.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -708,24 +708,26 @@ wxPdfTable::GetLastRowsOnPage() const
708708
const double yMax = pageHeight - breakMargin;
709709
const double firstBodyRowHeight = iterBodyFirst->second;
710710
const bool writeHeader = m_headRowLast > m_headRowFirst;
711-
double headerHeight = 0;
712-
//in case we have a line break and the table has a header, we need to consider the space of the header at the new page
713-
if (writeHeader)
711+
712+
//m_document->GetHeaderHeight() is header height minus top margin, so we have to consider top margin as well
713+
const double topTotalMargin = m_document->GetTopMargin() + m_document->GetHeaderHeight() + m_headHeight;
714+
715+
if (topTotalMargin + firstBodyRowHeight > yMax)
714716
{
715-
for (unsigned int headRow = m_headRowFirst; headRow < m_headRowLast; headRow++)
716-
{
717-
headerHeight += m_rowHeights.find(headRow)->second;
718-
}
717+
wxLogError(wxString(wxS("wxPdfDocument::wxPdfTable: ")) +
718+
wxString(_("Not possible to draw at least one table line on a page.")));
719+
return lastRows;
719720
}
721+
720722
double y = m_document->GetY();
721723

722724
//this means basically that we have a line break before drawing the table
723725
y += m_headHeight + firstBodyRowHeight;
724726
if (y > yMax)
725727
{
726728
lastRows.Add(m_headRowLast);
727-
//Maybe we have a header at the top of the next page
728-
y = m_document->GetHeaderHeight();
729+
730+
y = topTotalMargin;
729731
}
730732

731733
for (unsigned int row = m_bodyRowFirst + 1; row < m_bodyRowLast; ++row)
@@ -735,13 +737,8 @@ wxPdfTable::GetLastRowsOnPage() const
735737
{
736738
//since m_bodyRowLast and m_headRowLast are alway one behind last, last row on page is always one behind too.
737739
lastRows.Add(row);
738-
//Maybe we have a header at the top of the next page
739-
y = m_document->GetHeaderHeight();
740-
}
741-
if (writeHeader)
742-
{
743-
//consider the table header
744-
y += headerHeight;
740+
741+
y = topTotalMargin;
745742
}
746743
y += rowHeight;
747744
}

0 commit comments

Comments
 (0)