Lock page when changes are done in the SQL editor
[phpmyadmin.git] / libraries / PDF.php
blobefe9abfef3812111efb9908dfb8fa0a4f2d27129
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * TCPDF wrapper class.
6 * @package PhpMyAdmin
7 */
8 namespace PMA\libraries;
10 use TCPDF;
11 use TCPDF_FONTS;
13 /**
14 * PDF export base class providing basic configuration.
16 * @package PhpMyAdmin
18 class PDF extends TCPDF
20 var $footerset;
21 var $Alias = array();
23 /**
24 * PDF font to use.
26 const PMA_PDF_FONT = 'DejaVuSans';
28 /**
29 * Constructs PDF and configures standard parameters.
31 * @param string $orientation page orientation
32 * @param string $unit unit
33 * @param string $format the format used for pages
34 * @param boolean $unicode true means that the input text is unicode
35 * @param string $encoding charset encoding; default is UTF-8.
36 * @param boolean $diskcache if true reduce the RAM memory usage by caching
37 * temporary data on filesystem (slower).
38 * @param boolean $pdfa If TRUE set the document to PDF/A mode.
40 * @access public
42 public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
43 $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa=false
44 ) {
45 parent::__construct(
46 $orientation, $unit, $format, $unicode,
47 $encoding, $diskcache, $pdfa
49 $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
50 $this->AddFont('DejaVuSans', '', 'dejavusans.php');
51 $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
52 $this->SetFont(PDF::PMA_PDF_FONT, '', 14);
53 $this->setFooterFont(array(PDF::PMA_PDF_FONT, '', 14));
56 /**
57 * This function must be named "Footer" to work with the TCPDF library
59 * @return void
61 public function Footer()
63 // Check if footer for this page already exists
64 if (!isset($this->footerset[$this->page])) {
65 $this->SetY(-15);
66 $this->SetFont(PDF::PMA_PDF_FONT, '', 14);
67 $this->Cell(
68 0, 6,
69 __('Page number:') . ' '
70 . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),
71 'T', 0, 'C'
73 $this->Cell(0, 6, Util::localisedDate(), 0, 1, 'R');
74 $this->SetY(20);
76 // set footerset
77 $this->footerset[$this->page] = 1;
81 /**
82 * Function to set alias which will be expanded on page rendering.
84 * @param string $name name of the alias
85 * @param string $value value of the alias
87 * @return void
89 public function SetAlias($name, $value)
91 $name = TCPDF_FONTS::UTF8ToUTF16BE(
92 $name, false, true, $this->CurrentFont
94 $this->Alias[$name] = TCPDF_FONTS::UTF8ToUTF16BE(
95 $value, false, true, $this->CurrentFont
99 /**
100 * Improved with alias expanding.
102 * @return void
104 public function _putpages()
106 if (count($this->Alias) > 0) {
107 $nbPages = count($this->pages);
108 for ($n = 1; $n <= $nbPages; $n++) {
109 $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
112 parent::_putpages();
116 * Displays an error message
118 * @param string $error_message the error message
120 * @return void
122 public function Error($error_message = '')
124 Message::error(
125 __('Error while creating PDF:') . ' ' . $error_message
126 )->display();
127 exit;
131 * Sends file as a download to user.
133 * @param string $filename file name
135 * @return void
137 public function Download($filename)
139 $pdfData = $this->getPDFData();
140 Response::getInstance()->disable();
141 PMA_downloadHeader(
142 $filename,
143 'application/pdf',
144 strlen($pdfData)
146 echo $pdfData;