Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / PDF.class.php
blobfa4b48ac02c5ed3ef1c6164160bb358fb8f28fb6
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).
40 * @return void
41 * @access public
43 public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
44 $unicode = true, $encoding = 'UTF-8', $diskcache = false
45 ) {
46 parent::__construct();
47 $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
48 $this->AddFont('DejaVuSans', '', 'dejavusans.php');
49 $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
50 $this->SetFont(PMA_PDF_FONT, '', 14);
51 $this->setFooterFont(array(PMA_PDF_FONT, '', 14));
54 /**
55 * This function must be named "Footer" to work with the TCPDF library
57 * @return void
59 function Footer()
61 // Check if footer for this page already exists
62 if (!isset($this->footerset[$this->page])) {
63 $this->SetY(-15);
64 $this->SetFont(PMA_PDF_FONT, '', 14);
65 $this->Cell(0, 6, __('Page number:') . ' ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 'T', 0, 'C');
66 $this->Cell(0, 6, PMA_Util::localisedDate(), 0, 1, 'R');
67 $this->SetY(20);
69 // set footerset
70 $this->footerset[$this->page] = 1;
74 /**
75 * Function to test an empty string (was in tcpdf < 6.0)
77 * @param string $str to test
79 * @return boolean
81 public function empty_string($str) {
82 return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
85 /**
86 * Function to set alias which will be expanded on page rendering.
88 * @param string $name name of the alias
89 * @param string $value value of the alias
91 * @return void
93 function SetAlias($name, $value)
95 $this->Alias[$this->UTF8ToUTF16BE($name)] = $this->UTF8ToUTF16BE($value);
98 /**
99 * Improved with alias expading.
101 * @return void
103 function _putpages()
105 if (count($this->Alias) > 0) {
106 $nb = count($this->pages);
107 for ($n = 1;$n <= $nb;$n++) {
108 $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
111 parent::_putpages();
115 * Displays an error message
117 * @param string $error_message the error mesage
119 * @return void
121 function Error($error_message = '')
123 PMA_Message::error(
124 __('Error while creating PDF:') . ' ' . $error_message
125 )->display();
126 exit;
130 * Sends file as a download to user.
132 * @param string $filename file name
134 * @return void
136 function Download($filename)
138 $pdfData = $this->getPDFData();
139 PMA_Response::getInstance()->disable();
140 PMA_downloadHeader($filename, 'application/pdf', strlen($pdfData));
141 echo $pdfData;