Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically call and display the header and footer set in XML #5033

Open
wants to merge 1 commit into
base: 2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions app/Report/PdfRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,42 @@
// The last pictures page number
public int $lastpicpage = 0;

// The HEADER OR FOOTER to render
public bool $isHeaderOrFooter = false;

//The breakpage header y
public float $breakPageHeaderHeight = 0.0;

/**
* PDF Header -PDF
*
* @return void
*/
public function header(): void
public function header(): void //sfqas
{
foreach ($this->headerElements as $element) {
$isHeaderOrFooter = true;
foreach ($this->headerElements as $element) {
if ($element instanceof ReportBaseElement) {
$element->render($this);
$element->render($this,$isHeaderOrFooter);

Check failure on line 86 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 7.4)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 86 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.0)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 86 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.1)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 86 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 86 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.
} elseif ($element === 'footnotetexts') {
$this->footnotes();
} elseif ($element === 'addpage') {
$this->newPage();
}
}
$isHeaderOrFooter = false;
$this->breakPageHeaderHeight =$this->tcpdf->GetY();
}

/**
* PDF Body -PDF
*
* @return void
*/
public function body(): void
public function body(): void // //sfqas
{
$this->tcpdf->AddPage();

// $this->tcpdf->AddPage();
$this->newPage();
foreach ($this->bodyElements as $element) {
if ($element instanceof ReportBaseElement) {
$element->render($this);
Expand Down Expand Up @@ -130,17 +139,19 @@
*
* @return void
*/
public function footer(): void
public function footer(): void //sfqas
{
foreach ($this->footerElements as $element) {
$isHeaderOrFooter = true;
foreach ($this->footerElements as $element) {
if ($element instanceof ReportBaseElement) {
$element->render($this);
$element->render($this,$isHeaderOrFooter);

Check failure on line 147 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 7.4)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 147 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.0)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 147 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.1)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 147 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.

Check failure on line 147 in app/Report/PdfRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Method Fisharebest\Webtrees\Report\ReportBaseElement::render() invoked with 2 parameters, 1 required.
} elseif ($element === 'footnotetexts') {
$this->footnotes();
} elseif ($element === 'addpage') {
$this->newPage();
}
}
$isHeaderOrFooter = false;
}

/**
Expand Down Expand Up @@ -317,12 +328,18 @@
*
* @return void
*/
public function newPage(): void
public function newPage(): void // // //sfqas
{
if ($this->lastpicpage > $this->tcpdf->getPage()) {
$this->tcpdf->setPage($this->lastpicpage);
}
$this->tcpdf->AddPage();

$this->header();
// $this->tcpdf->setY($this->tcpdf->getPageHeight() - 75);
$this->tcpdf->setY($this->tcpdf->getPageHeight()-$this->footer_margin-55);
$this->footer();
$this->tcpdf->setY($this->breakPageHeaderHeight);
}

/**
Expand All @@ -332,9 +349,22 @@
*
* @return bool true in case of page break, false otherwise
*/
public function checkPageBreakPDF(float $height): bool
public function checkPageBreakPDF(float $height): bool // // //sfqas
{
return $this->tcpdf->checkPageBreak($height);
// return $this->tcpdf->checkPageBreak($height);
$isPageBreaked = false;
if(!$this->isHeaderOrFooter){
$isPageBreaked = $this->tcpdf->checkPageBreak($height);
$this->tcpdf->setY($this->header_margin);
$this->header();
// $this->tcpdf->setY($this->tcpdf->getPageHeight() - 75);
$this->tcpdf->setY($this->tcpdf->getPageHeight()-$this->footer_margin-55);
$this->footer();
$this->tcpdf->setY($this->breakPageHeaderHeight);
return $isPageBreaked ;
}else{
return false;

Check warning on line 366 in app/Report/PdfRenderer.php

View check run for this annotation

Codecov / codecov/patch

app/Report/PdfRenderer.php#L366

Added line #L366 was not covered by tests
}
}

/**
Expand Down Expand Up @@ -378,6 +408,9 @@
$this->tcpdf->setKeywords($this->rkeywords);
$this->tcpdf->setHeaderData('', 0, $this->title);
$this->tcpdf->setHeaderFont([$this->default_font, '', $this->default_font_size]);
// // remove default header/footer
$this->tcpdf->setPrintHeader(false);
$this->tcpdf->setPrintFooter(false);

if ($this->show_generated_by) {
// The default style name for Generated by.... is 'genby'
Expand Down
11 changes: 7 additions & 4 deletions app/Report/ReportPdfCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ReportPdfCell extends ReportBaseCell
*
* @return void
*/
public function render($renderer): void
public function render($renderer, bool $headerorfoot=false): void //sfqas
{
$temptext = str_replace('#PAGENUM#', (string) $renderer->tcpdf->PageNo(), $this->text);
// underline «title» part of Source item
Expand Down Expand Up @@ -125,9 +125,12 @@ public function render($renderer): void
$cHT += $cM['cell'] * 2;
}
// Add a new page if needed
if ($renderer->checkPageBreakPDF($cHT)) {
$this->top = $renderer->tcpdf->GetY();
}
//sfqas
if ($renderer->tcpdf->checkPageBreak($cHT,null,false) and !$headerorfoot){
if ($renderer->checkPageBreakPDF($cHT)) {
$this->top = $renderer->tcpdf->GetY();
}
}
$temptext = RightToLeftSupport::spanLtrRtl($temptext);
}
// HTML ready - last value is true
Expand Down
7 changes: 4 additions & 3 deletions app/Report/ReportPdfImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
*
* @return void
*/
public function render($renderer): void
public function render($renderer,bool $headerorfoot=false): void //sfqas

Check warning on line 34 in app/Report/ReportPdfImage.php

View check run for this annotation

Codecov / codecov/patch

app/Report/ReportPdfImage.php#L34

Added line #L34 was not covered by tests
{
static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;

// Check for a pagebreak first
if ($renderer->checkPageBreakPDF($this->height + 5)) {
$this->y = $renderer->tcpdf->GetY();
if ($renderer->tcpdf->checkPageBreak($this->height + 5,null,false) and !$headerorfoot){ //sfqas
$renderer->checkPageBreakPDF($this->height + 5);
$this->y = $renderer->tcpdf->GetY();

Check warning on line 41 in app/Report/ReportPdfImage.php

View check run for this annotation

Codecov / codecov/patch

app/Report/ReportPdfImage.php#L39-L41

Added lines #L39 - L41 were not covered by tests
}

$curx = $renderer->tcpdf->GetX();
Expand Down
12 changes: 7 additions & 5 deletions app/Report/ReportPdfTextBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ReportPdfTextBox extends ReportBaseTextbox
*
* @return void
*/
public function render($renderer): void
public function render($renderer,bool $headerorfoot=false): void //sfqas
{
$newelements = [];
$lastelement = '';
Expand Down Expand Up @@ -224,11 +224,13 @@ public function render($renderer): void
}
// Add a new page if needed
if ($this->pagecheck) {
// Reset last cell height or Header/Footer will inherit it, in case of pagebreak
$renderer->lastCellHeight = 0;
if ($renderer->checkPageBreakPDF($cH)) {
$cY = $renderer->tcpdf->GetY();
if ($renderer->tcpdf->checkPageBreak($cH,null,false) and !$headerorfoot){
// Reset last cell height or Header/Footer will inherit it, in case of pagebreak
$renderer->lastCellHeight = 0;
if ($renderer->checkPageBreakPDF($cH)) {
$cY = $renderer->tcpdf->GetY();
}
}
}

// Setup the border and background color
Expand Down
Loading