mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-70117 dataformat_pdf: Fix content overflow when headers are involved
This commit is contained in:
parent
d330035f11
commit
8d025b449e
@ -90,7 +90,7 @@ class writer extends \core\dataformat\base {
|
||||
$this->colwidth = $pagewidth / count($columns);
|
||||
$this->columns = $columns;
|
||||
|
||||
$this->print_heading();
|
||||
$this->print_heading($this->pdf);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,10 +137,12 @@ class writer extends \core\dataformat\base {
|
||||
$pdf2->startTransaction();
|
||||
$numpages = $pdf2->getNumPages();
|
||||
$pdf2->AddPage('L');
|
||||
$this->print_heading($pdf2);
|
||||
$pdf2->writeHTMLCell($this->colwidth, 0, '', '', $cell, 1, 1, false, true, 'L');
|
||||
$pagesadded = $pdf2->getNumPages() - $numpages;
|
||||
$pageheight = $pdf2->getPageHeight() - $pdf2->getMargins()['top'] - $pdf2->getMargins()['bottom'];
|
||||
$cellheight = ($pagesadded - 1) * $pageheight + $pdf2->getLastH();
|
||||
$margins = $pdf2->getMargins();
|
||||
$pageheight = $pdf2->getPageHeight() - $margins['top'] - $margins['bottom'];
|
||||
$cellheight = ($pagesadded - 1) * $pageheight + $pdf2->getY() - $margins['top'] - $this->get_heading_height();
|
||||
$rowheight = max($rowheight, $cellheight);
|
||||
$pdf2->rollbackTransaction();
|
||||
}
|
||||
@ -149,7 +151,7 @@ class writer extends \core\dataformat\base {
|
||||
if ($this->pdf->getNumPages() > 1 &&
|
||||
($this->pdf->GetY() + $rowheight + $margins['bottom'] > $this->pdf->getPageHeight())) {
|
||||
$this->pdf->AddPage('L');
|
||||
$this->print_heading();
|
||||
$this->print_heading($this->pdf);
|
||||
}
|
||||
|
||||
// Get the last key for this record.
|
||||
@ -186,25 +188,36 @@ class writer extends \core\dataformat\base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the heading row.
|
||||
* Prints the heading row for a given PDF.
|
||||
*
|
||||
* @param \pdf $pdf A pdf to print headings in
|
||||
*/
|
||||
private function print_heading() {
|
||||
$fontfamily = $this->pdf->getFontFamily();
|
||||
$fontstyle = $this->pdf->getFontStyle();
|
||||
$this->pdf->SetFont($fontfamily, 'B');
|
||||
$rowheight = 0;
|
||||
foreach ($this->columns as $columns) {
|
||||
$rowheight = max($rowheight, $this->pdf->getStringHeight($this->colwidth, $columns, false, true, '', 1));
|
||||
}
|
||||
private function print_heading(\pdf $pdf) {
|
||||
$fontfamily = $pdf->getFontFamily();
|
||||
$fontstyle = $pdf->getFontStyle();
|
||||
$pdf->SetFont($fontfamily, 'B');
|
||||
|
||||
$total = count($this->columns);
|
||||
$counter = 1;
|
||||
foreach ($this->columns as $columns) {
|
||||
$nextposition = ($counter == $total) ? 1 : 0;
|
||||
$this->pdf->Multicell($this->colwidth, $rowheight, $columns, 1, 'C', true, $nextposition);
|
||||
$pdf->Multicell($this->colwidth, $this->get_heading_height(), $columns, 1, 'C', true, $nextposition);
|
||||
$counter++;
|
||||
}
|
||||
|
||||
$this->pdf->SetFont($fontfamily, $fontstyle);
|
||||
$pdf->SetFont($fontfamily, $fontstyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the heading height.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function get_heading_height() {
|
||||
$height = 0;
|
||||
foreach ($this->columns as $columns) {
|
||||
$height = max($height, $this->pdf->getStringHeight($this->colwidth, $columns, false, true, '', 1));
|
||||
}
|
||||
return $height;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user