Skip to content

Commit

Permalink
Updated PDF header and footer.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Feb 6, 2025
1 parent 173d827 commit e30aca6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 35 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 23 additions & 17 deletions src/Report/ReportFooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace App\Report;

use App\Pdf\PdfFont;
use App\Pdf\PdfStyle;
use App\Utils\FormatUtils;
use fpdf\Enums\PdfTextAlignment;
use fpdf\PdfBorder;
use fpdf\PdfDocument;

/**
* Class to output footer in PDF documents.
Expand Down Expand Up @@ -71,35 +71,41 @@ public function setContent(string $content, ?string $url = null): self
return $this;
}

/**
* Gets the formatted current date.
*/
private function getDate(): string
private function outputContent(float $width): self
{
return $this->date ??= FormatUtils::formatDateTime(new \DateTime());
return $this->outputText($this->content, $width, PdfTextAlignment::CENTER, $this->url);
}

/**
* Gets the formatted pages.
*/
private function getPages(): string
private function outputDate(float $width): void
{
$text = $this->date ??= FormatUtils::formatDateTime(new \DateTime());

$this->outputText($text, $width, PdfTextAlignment::RIGHT);
}

private function outputPages(float $width): self
{
$parent = $this->parent;
$text = $parent->trans('report.page', [
'{0}' => $parent->getPage(),
'{1}' => $parent->getAliasNumberPages(),
]);

return $parent->trans('report.page', ['{0}' => $parent->getPage(), '{1}' => '{nb}']);
return $this->outputText($text, $width, PdfTextAlignment::LEFT);
}

/**
* Output the given text.
*/
private function outputText(string $text, float $width, PdfTextAlignment $align, ?string $link = null): self
private function outputText(?string $text, float $width, PdfTextAlignment $align, ?string $link = null): self
{
$text ??= '';
$this->parent->cell(
width: $width,
text: $text,
border: PdfBorder::top(),
align: $align,
link: $link
link: '' !== $text ? $link : null
);

return $this;
Expand All @@ -110,10 +116,10 @@ private function outputTexts(): void
$parent = $this->parent;
$parent->setY(-self::FOOTER_OFFSET);
$width = $parent->getPrintableWidth() / 3.0;
PdfStyle::default()->setFontSize(PdfFont::DEFAULT_SIZE - 1.0)->apply($parent);
$this->outputText($this->getPages(), $width, PdfTextAlignment::LEFT)
->outputText($this->content ?? '', $width, PdfTextAlignment::CENTER, $this->url)
->outputText($this->getDate(), $width, PdfTextAlignment::RIGHT);
PdfStyle::default()->setFontSize(PdfDocument::LINE_HEIGHT - 1.0)->apply($parent);
$this->outputPages($width)
->outputContent($width)
->outputDate($width);
$parent->resetStyle();
}
}
6 changes: 4 additions & 2 deletions src/Report/ReportHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private function outputDescription(): void
if (null === $description) {
return;
}

$this->applySmallStyle();
$this->parent->multiCell(
height: self::SMALL_HEIGHT,
Expand Down Expand Up @@ -253,14 +254,15 @@ private function outputText(
PdfMove $move = PdfMove::RIGHT,
string|int|null $link = null
): void {
$text ??= '';
$this->parent->cell(
width: $width,
height: $height,
text: $text ?? '',
text: $text,
border: $border,
move: $move,
align: $align,
link: $link
link: '' !== $text ? $link : null
);
}

Expand Down
11 changes: 6 additions & 5 deletions vendor-bin/psalm/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e30aca6

Please sign in to comment.