Translated using Weblate (Kurdish Sorani)
[phpmyadmin.git] / libraries / PDF.class.php
blobe0c2344b12a5279fa1940faa701cdd8ed0a4f4a7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * TCPDF wrapper class.
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once TCPDF_INC;
14 /**
15 * PDF font to use.
17 define('PMA_PDF_FONT', 'DejaVuSans');
19 /**
20 * PDF export base class providing basic configuration.
22 * @package PhpMyAdmin
24 class PMA_PDF extends TCPDF
26 var $footerset;
27 var $Alias = array();
29 /**
30 * Constructs PDF and configures standard parameters.
32 * @param string $orientation page orientation
33 * @param string $unit unit
34 * @param mixed $format the format used for pages
35 * @param boolean $unicode true means that the input text is unicode
36 * @param string $encoding charset encoding; default is UTF-8.
37 * @param boolean $diskcache if true reduce the RAM memory usage by caching
38 * temporary data on filesystem (slower).
39 * @param boolean $pdfa If TRUE set the document to PDF/A mode.
41 * @return void
42 * @access public
44 public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
45 $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa=false
46 ) {
47 parent::__construct(
48 $orientation, $unit, $format, $unicode,
49 $encoding, $diskcache, $pdfa
51 $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
52 $this->AddFont('DejaVuSans', '', 'dejavusans.php');
53 $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
54 $this->SetFont(PMA_PDF_FONT, '', 14);
55 $this->setFooterFont(array(PMA_PDF_FONT, '', 14));
58 /**
59 * This function must be named "Footer" to work with the TCPDF library
61 * @return void
63 function Footer()
65 // Check if footer for this page already exists
66 if (!isset($this->footerset[$this->page])) {
67 $this->SetY(-15);
68 $this->SetFont(PMA_PDF_FONT, '', 14);
69 $this->Cell(
70 0, 6,
71 __('Page number:') . ' '
72 . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),
73 'T', 0, 'C'
75 $this->Cell(0, 6, PMA_Util::localisedDate(), 0, 1, 'R');
76 $this->SetY(20);
78 // set footerset
79 $this->footerset[$this->page] = 1;
83 /**
84 * Function to set alias which will be expanded on page rendering.
86 * @param string $name name of the alias
87 * @param string $value value of the alias
89 * @return void
91 function SetAlias($name, $value)
93 $name = TCPDF_FONTS::UTF8ToUTF16BE(
94 $name, false, true, $this->CurrentFont
96 $this->Alias[$name] = TCPDF_FONTS::UTF8ToUTF16BE(
97 $value, false, true, $this->CurrentFont
102 * Improved with alias expading.
104 * @return void
106 function _putpages()
108 if (count($this->Alias) > 0) {
109 $nb = count($this->pages);
110 for ($n = 1;$n <= $nb;$n++) {
111 $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
114 parent::_putpages();
118 * Displays an error message
120 * @param string $error_message the error mesage
122 * @return void
124 function Error($error_message = '')
126 PMA_Message::error(
127 __('Error while creating PDF:') . ' ' . $error_message
128 )->display();
129 exit;
133 * Sends file as a download to user.
135 * @param string $filename file name
137 * @return void
139 function Download($filename)
141 $pdfData = $this->getPDFData();
142 PMA_Response::getInstance()->disable();
143 PMA_downloadHeader($filename, 'application/pdf', strlen($pdfData));
144 echo $pdfData;