6 declare(strict_types
=1);
19 * PDF export base class providing basic configuration.
21 class Pdf
extends TCPDF
24 public array $footerset = [];
27 public array $alias = [];
32 public const PMA_PDF_FONT
= 'DejaVuSans';
35 * Constructs PDF and configures standard parameters.
37 * @param string $orientation page orientation
38 * @param string $unit unit
39 * @param string $format the format used for pages
40 * @param bool $unicode true means that the input text is unicode
41 * @param string $encoding charset encoding; default is UTF-8.
42 * @param bool $diskcache DEPRECATED TCPDF FEATURE
43 * @param false|int $pdfa If not false, set the document to PDF/A mode and the good version (1 or 3)
47 * @infection-ignore-all
49 public function __construct(
50 string $orientation = 'P',
52 string $format = 'A4',
54 string $encoding = 'UTF-8',
55 bool $diskcache = false,
56 false|
int $pdfa = false,
58 parent
::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);
60 $this->setAuthor('phpMyAdmin ' . Version
::VERSION
);
61 $this->AddFont('DejaVuSans', '', 'dejavusans.php');
62 $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
63 $this->setFont(self
::PMA_PDF_FONT
, '', 14);
64 $this->setFooterFont([self
::PMA_PDF_FONT
, '', 14]);
68 * This function must be named "Footer" to work with the TCPDF library
70 // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
71 public function Footer(): void
73 // Check if footer for this page already exists
74 if (isset($this->footerset
[$this->page
])) {
79 $this->setFont(self
::PMA_PDF_FONT
, '', 14);
83 __('Page number:') . ' '
84 . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),
89 $this->Cell(0, 6, Util
::localisedDate(), 0, 1, 'R');
93 $this->footerset
[$this->page
] = 1;
97 * Function to set alias which will be expanded on page rendering.
99 * @param string $name name of the alias
100 * @param string $value value of the alias
102 public function setAlias(string $name, string $value): void
104 // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
105 $name = TCPDF_FONTS
::UTF8ToUTF16BE($name, false, true, $this->CurrentFont
);
106 $this->alias
[$name] = TCPDF_FONTS
::UTF8ToUTF16BE($value, false, true, $this->CurrentFont
);
110 // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
113 * Improved with alias expanding.
115 public function _putpages(): void
117 if ($this->alias
!== []) {
118 $nbPages = count($this->pages
);
119 for ($n = 1; $n <= $nbPages; $n++
) {
120 $this->pages
[$n] = strtr($this->pages
[$n], $this->alias
);
130 * Displays an error message
132 * @param string $msg the error message
134 // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
135 public function Error(mixed $msg = ''): never
138 __('Error while creating PDF:') . ' ' . $msg,
140 ResponseRenderer
::getInstance()->callExit();