use Galette\Entity\PdfModel;
use Analog\Analog;
use Slim\Routing\RouteParser;
+use TCPDF;
/*
* TCPDF configuration file for Galette
* @author Johan Cwiklinski <johan@x-tnd.be>
*/
-class Pdf extends \TCPDF
+class Pdf extends TCPDF
{
public const FONT = 'DejaVuSans';
public const FONT_SIZE = 10;
private PdfModel $model;
private bool $paginated = false;
protected string $filename;
+ private bool $has_footer = true;
+ protected float $footer_height;
/**
* Main constructor, set creator and author
$this->model = $model;
$this->SetTitle($this->model->htitle);
}
+
+ $this->init();
+ if ($this->has_footer) {
+ $this->calculateFooterHeight();
+ }
+ }
+
+ /**
+ * Initialize PDF
+ *
+ * @return void
+ */
+ public function init(): void
+ {
+ $this->Open();
+ $this->AddPage();
+ }
+
+ /**
+ * No header
+ *
+ * @return void
+ */
+ protected function setNoHeader(): void
+ {
+ $this->SetPrintHeader(false);
+ $this->setHeaderMargin(0);
+ }
+
+ /**
+ * No footer
+ *
+ * @return void
+ */
+ protected function setNoFooter(): void
+ {
+ $this->SetPrintFooter(false);
+ $this->setFooterMargin(0);
+ $this->has_footer = false;
+ }
+
+ /**
+ * Calculate footer height
+ *
+ * @return void
+ */
+ private function calculateFooterHeight(): void
+ {
+ $pdf = clone $this;
+ $y_orig = $pdf->getY();
+ $this->Footer($pdf);
+ $y_end = $pdf->getY();
+ $this->footer_height = $y_end - $y_orig;
}
/**
/**
* Draws PDF page footer
*
+ * @param ?TCPDF $pdf PDF instance
+ *
* @return void
*/
- public function Footer(): void // phpcs:ignore PSR1.Methods.CamelCapsMethodName
+ public function Footer(TCPDF $pdf = null): void // phpcs:ignore PSR1.Methods.CamelCapsMethodName
{
- $this->SetY(-20);
+ if ($pdf === null) {
+ $pdf = $this;
+ $pdf->SetY(-($this->footer_height + 15));
+ }
if (isset($this->model)) {
$hfooter = '';
if (trim($this->model->hstyles) !== '') {
$hfooter .= "<style>\n" . $this->model->hstyles . "\n</style>\n\n";
}
$hfooter .= $this->model->hfooter;
- $this->writeHtml($hfooter);
+ $pdf->writeHtml($hfooter);
} else {
- $this->SetFont(self::FONT, '', self::FONT_SIZE - 2);
- $this->SetTextColor(0, 0, 0);
-
- $name = preg_replace(
- '/%s/',
- $this->preferences->pref_nom,
- _T("Association %s")
- );
-
$address = $this->preferences->getPostalAddress();
+ $hfooter = '<style>div#pdf_footer {text-align: center;font-size: 0.7em;}</style>';
+ $hfooter .= '<div id="pdf_footer">' . nl2br($address) . '</div>';
+ $pdf->writeHTML($hfooter);
+ }
- $this->MultiCell(
+ if ($this->paginated) {
+ $pdf->SetFont(self::FONT, '', self::FONT_SIZE - 3);
+ $pdf->Ln();
+ $pdf->Cell(
0,
4,
- $address,
+ $this->getAliasRightShift() . $this->PageNo() .
+ '/' . $this->getAliasNbPages(),
0,
- 'C'
+ 1,
+ ($this->i18n->isRTL() ? 'L' : 'R')
);
-
- if ($this->paginated) {
- $this->SetFont(self::FONT, '', self::FONT_SIZE - 3);
- $this->Ln();
- $this->Cell(
- 0,
- 4,
- $this->getAliasRightShift() . $this->PageNo() .
- '/' . $this->getAliasNbPages(),
- 0,
- 1,
- ($this->i18n->isRTL() ? 'L' : 'R')
- );
- }
}
}
use Galette\Core\Db;
use Galette\Core\Preferences;
-use Galette\Core\PrintLogo;
use Galette\Entity\Adherent;
use Galette\Entity\PdfModel;
-use Analog\Analog;
/**
* Attendance sheet
}
parent::__construct($prefs, $model);
- $this->init();
+ // Enable Auto Page breaks
+ $this->SetAutoPageBreak(true, $this->footer_height + 10);
}
+
/**
* Initialize PDF
*
* @return void
*/
- private function init(): void
+ public function init(): void
{
// Set document information
$this->SetSubject(_T("Generated by Galette"));
$this->SetKeywords(_T("Attendance sheet"));
- // No hearders and footers
$this->setHeaderMargin(10);
// Set colors
$this->SetDrawColor(160, 160, 160);
$this->SetTextColor(0);
$this->SetFont(Pdf::FONT, '', Pdf::FONT_SIZE - 2);
+
+ //enable pagination
+ $this->showPagination();
+
+ parent::init();
}
/**
*/
public function drawSheet(array $members): void
{
- $this->Open();
- $this->AddPage();
$this->PageHeader($this->doc_title);
if ($this->sheet_date) {
parent::__construct($prefs, $this->model);
- $this->Open();
-
- $this->AddPage();
$this->PageHeader();
$this->PageBody();
}
namespace Galette\IO;
use Galette\Core\Preferences;
-use Galette\Core\PrintLogo;
use Analog\Analog;
use Galette\Core\Login;
use Galette\Entity\Group;
*/
public function __construct(Preferences $prefs)
{
- parent::__construct($prefs);
$this->filename = __('groups_list') . '.pdf';
- $this->init();
+ parent::__construct($prefs);
+ // Enable Auto Page breaks
+ $this->SetAutoPageBreak(true, $this->footer_height + 10);
}
/**
*
* @return void
*/
- private function init(): void
+ public function init(): void
{
// Set document information
$this->doc_title = _T("Members by groups");
$this->SetTitle($this->doc_title);
$this->SetSubject(_T("Generated by Galette"));
- // Enable Auto Page breaks
- $this->SetAutoPageBreak(true, 20);
-
// Set colors
$this->SetTextColor(0, 0, 0);
// Set margins
- $this->setMargins(10, 20);
+ $this->setMargins(10, 25);
$this->setHeaderMargin(10);
// Set font
//enable pagination
$this->showPagination();
+
+ parent::init();
}
/**
*/
public function draw(array $groups, Login $login): void
{
- $this->Open();
- $this->AddPage();
$this->PageHeader($this->doc_title);
$first = true;
$this->Cell(30, 7, _T("Phone"), 1, 0, 'C', true);
$this->Cell(30, 7, _T("GSM"), 1, 1, 'C', true);
- $this->SetFont('', 'B');
+ $this->SetFont('', '');
$members = $group->getMembers();
*/
public function __construct(Preferences $prefs)
{
- parent::__construct($prefs);
$this->setRTL(false);
$this->filename = __('cards') . '.pdf';
- $this->init();
+ parent::__construct($prefs);
}
+
/**
* Initialize PDF
*
* @return void
*/
- private function init(): void
+ public function init(): void
{
// Set document information
$this->SetTitle(_T("Member's Cards"));
$this->SetSubject(_T("Generated by Galette"));
$this->SetKeywords(_T("Cards"));
- // No hearders and footers
- $this->SetPrintHeader(false);
- $this->SetPrintFooter(false);
- $this->setFooterMargin(0);
- $this->setHeaderMargin(0);
+ // No headers and footers
+ $this->setNoHeader();
+ $this->setNoFooter();
// Show full page
$this->SetDisplayMode('fullpage');
// Card width
$this->wi = self::getWidth();
- // Card heigth
+ // Card height
$this->he = self::getHeight();
// Number of colons
$this->nbcol = self::getCols();
*/
public function __construct(Preferences $prefs)
{
- parent::__construct($prefs);
$this->setRTL(false);
$this->filename = __('labels_print_filename') . '.pdf';
- $this->init();
+ parent::__construct($prefs);
}
/**
*
* @return void
*/
- private function init(): void
+ public function init(): void
{
// Set document information
$this->SetTitle(_T("Member's Labels"));
$this->SetSubject(_T("Generated by Galette"));
$this->SetKeywords(_T("Labels"));
- // No hearders and footers
- $this->SetPrintHeader(false);
- $this->SetPrintFooter(false);
- $this->setFooterMargin(0);
- $this->setHeaderMargin(0);
+ // No headers and footers
+ $this->setNoHeader();
+ $this->setNoFooter();
// Show full page
$this->SetDisplayMode('fullpage');