Minor improvement to prior commit.
[openemr.git] / phpmyadmin / libraries / PDF.class.php
blobb6f00e663386157441460059b160b0c4cc1feb48
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 string $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 * @access public
43 public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
44 $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa=false
45 ) {
46 parent::__construct(
47 $orientation, $unit, $format, $unicode,
48 $encoding, $diskcache, $pdfa
50 $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
51 $this->AddFont('DejaVuSans', '', 'dejavusans.php');
52 $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
53 $this->SetFont(PMA_PDF_FONT, '', 14);
54 $this->setFooterFont(array(PMA_PDF_FONT, '', 14));
57 /**
58 * This function must be named "Footer" to work with the TCPDF library
60 * @return void
62 public function Footer()
64 // Check if footer for this page already exists
65 if (!isset($this->footerset[$this->page])) {
66 $this->SetY(-15);
67 $this->SetFont(PMA_PDF_FONT, '', 14);
68 $this->Cell(
69 0, 6,
70 __('Page number:') . ' '
71 . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),
72 'T', 0, 'C'
74 $this->Cell(0, 6, PMA_Util::localisedDate(), 0, 1, 'R');
75 $this->SetY(20);
77 // set footerset
78 $this->footerset[$this->page] = 1;
82 /**
83 * Function to set alias which will be expanded on page rendering.
85 * @param string $name name of the alias
86 * @param string $value value of the alias
88 * @return void
90 public function SetAlias($name, $value)
92 $name = TCPDF_FONTS::UTF8ToUTF16BE(
93 $name, false, true, $this->CurrentFont
95 $this->Alias[$name] = TCPDF_FONTS::UTF8ToUTF16BE(
96 $value, false, true, $this->CurrentFont
101 * Improved with alias expanding.
103 * @return void
105 public function _putpages()
107 if (count($this->Alias) > 0) {
108 $nbPages = count($this->pages);
109 for ($n = 1; $n <= $nbPages; $n++) {
110 $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
113 parent::_putpages();
117 * Displays an error message
119 * @param string $error_message the error message
121 * @return void
123 public function Error($error_message = '')
125 PMA_Message::error(
126 __('Error while creating PDF:') . ' ' . $error_message
127 )->display();
128 exit;
132 * Sends file as a download to user.
134 * @param string $filename file name
136 * @return void
138 public function Download($filename)
140 $pdfData = $this->getPDFData();
141 PMA_Response::getInstance()->disable();
142 PMA_downloadHeader(
143 $filename,
144 'application/pdf',
145 /*overload*/mb_strlen($pdfData)
147 echo $pdfData;