Fix #15621 - Support CloudFront-Forwarded-Proto header
[phpmyadmin.git] / libraries / classes / Pdf.php
blob8ab3f1bf99e7cc0335e4d759dc9a45feebbec6a7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * TCPDF wrapper class.
6 * @package PhpMyAdmin
7 */
8 namespace PhpMyAdmin;
10 use PhpMyAdmin\Core;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Util;
14 use TCPDF;
15 use TCPDF_FONTS;
17 /**
18 * PDF export base class providing basic configuration.
20 * @package PhpMyAdmin
22 class Pdf extends TCPDF
24 var $footerset;
25 var $Alias = array();
27 /**
28 * PDF font to use.
30 const PMA_PDF_FONT = 'DejaVuSans';
32 /**
33 * Constructs PDF and configures standard parameters.
35 * @param string $orientation page orientation
36 * @param string $unit unit
37 * @param string $format the format used for pages
38 * @param boolean $unicode true means that the input text is unicode
39 * @param string $encoding charset encoding; default is UTF-8.
40 * @param boolean $diskcache if true reduce the RAM memory usage by caching
41 * temporary data on filesystem (slower).
42 * @param boolean $pdfa If TRUE set the document to PDF/A mode.
44 * @access public
46 public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
47 $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa=false
48 ) {
49 parent::__construct(
50 $orientation, $unit, $format, $unicode,
51 $encoding, $diskcache, $pdfa
53 $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
54 $this->AddFont('DejaVuSans', '', 'dejavusans.php');
55 $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
56 $this->SetFont(Pdf::PMA_PDF_FONT, '', 14);
57 $this->setFooterFont(array(Pdf::PMA_PDF_FONT, '', 14));
60 /**
61 * This function must be named "Footer" to work with the TCPDF library
63 * @return void
65 // @codingStandardsIgnoreLine
66 public function Footer()
68 // Check if footer for this page already exists
69 if (!isset($this->footerset[$this->page])) {
70 $this->SetY(-15);
71 $this->SetFont(Pdf::PMA_PDF_FONT, '', 14);
72 $this->Cell(
73 0, 6,
74 __('Page number:') . ' '
75 . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),
76 'T', 0, 'C'
78 $this->Cell(0, 6, Util::localisedDate(), 0, 1, 'R');
79 $this->SetY(20);
81 // set footerset
82 $this->footerset[$this->page] = 1;
86 /**
87 * Function to set alias which will be expanded on page rendering.
89 * @param string $name name of the alias
90 * @param string $value value of the alias
92 * @return void
94 public function setAlias($name, $value)
96 $name = TCPDF_FONTS::UTF8ToUTF16BE(
97 $name, false, true, $this->CurrentFont
99 $this->Alias[$name] = TCPDF_FONTS::UTF8ToUTF16BE(
100 $value, false, true, $this->CurrentFont
105 * Improved with alias expanding.
107 * @return void
109 public function _putpages()
111 if (count($this->Alias) > 0) {
112 $nbPages = count($this->pages);
113 for ($n = 1; $n <= $nbPages; $n++) {
114 $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
117 parent::_putpages();
121 * Displays an error message
123 * @param string $error_message the error message
125 * @return void
127 // @codingStandardsIgnoreLine
128 public function Error($error_message = '')
130 Message::error(
131 __('Error while creating PDF:') . ' ' . $error_message
132 )->display();
133 exit;
137 * Sends file as a download to user.
139 * @param string $filename file name
141 * @return void
143 public function download($filename)
145 $pdfData = $this->getPDFData();
146 Response::getInstance()->disable();
147 Core::downloadHeader(
148 $filename,
149 'application/pdf',
150 strlen($pdfData)
152 echo $pdfData;