PDF.class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * TCPDF wrapper class.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. require_once TCPDF_INC;
  12. /**
  13. * PDF font to use.
  14. */
  15. define('PMA_PDF_FONT', 'DejaVuSans');
  16. /**
  17. * PDF export base class providing basic configuration.
  18. *
  19. * @package PhpMyAdmin
  20. */
  21. class PMA_PDF extends TCPDF
  22. {
  23. var $footerset;
  24. var $Alias = array();
  25. /**
  26. * Constructs PDF and configures standard parameters.
  27. *
  28. * @param string $orientation page orientation
  29. * @param string $unit unit
  30. * @param mixed $format the format used for pages
  31. * @param boolean $unicode true means that the input text is unicode
  32. * @param string $encoding charset encoding; default is UTF-8.
  33. * @param boolean $diskcache if true reduce the RAM memory usage by caching
  34. * temporary data on filesystem (slower).
  35. *
  36. * @return void
  37. * @access public
  38. */
  39. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
  40. $unicode = true, $encoding = 'UTF-8', $diskcache = false
  41. ) {
  42. parent::__construct();
  43. $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
  44. $this->AddFont('DejaVuSans', '', 'dejavusans.php');
  45. $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
  46. $this->SetFont(PMA_PDF_FONT, '', 14);
  47. $this->setFooterFont(array(PMA_PDF_FONT, '', 14));
  48. }
  49. /**
  50. * This function must be named "Footer" to work with the TCPDF library
  51. *
  52. * @return void
  53. */
  54. function Footer()
  55. {
  56. // Check if footer for this page already exists
  57. if (!isset($this->footerset[$this->page])) {
  58. $this->SetY(-15);
  59. $this->SetFont(PMA_PDF_FONT, '', 14);
  60. $this->Cell(0, 6, __('Page number:') . ' ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 'T', 0, 'C');
  61. $this->Cell(0, 6, PMA_Util::localisedDate(), 0, 1, 'R');
  62. $this->SetY(20);
  63. // set footerset
  64. $this->footerset[$this->page] = 1;
  65. }
  66. }
  67. /**
  68. * Function to test an empty string (was in tcpdf < 6.0)
  69. *
  70. * @param string $str to test
  71. *
  72. * @return boolean
  73. */
  74. public function empty_string($str) {
  75. return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
  76. }
  77. /**
  78. * Function to set alias which will be expanded on page rendering.
  79. *
  80. * @param string $name name of the alias
  81. * @param string $value value of the alias
  82. *
  83. * @return void
  84. */
  85. function SetAlias($name, $value)
  86. {
  87. $this->Alias[$this->UTF8ToUTF16BE($name)] = $this->UTF8ToUTF16BE($value);
  88. }
  89. /**
  90. * Improved with alias expading.
  91. *
  92. * @return void
  93. */
  94. function _putpages()
  95. {
  96. if (count($this->Alias) > 0) {
  97. $nb = count($this->pages);
  98. for ($n = 1;$n <= $nb;$n++) {
  99. $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
  100. }
  101. }
  102. parent::_putpages();
  103. }
  104. /**
  105. * Displays an error message
  106. *
  107. * @param string $error_message the error mesage
  108. *
  109. * @return void
  110. */
  111. function Error($error_message = '')
  112. {
  113. PMA_Message::error(
  114. __('Error while creating PDF:') . ' ' . $error_message
  115. )->display();
  116. exit;
  117. }
  118. /**
  119. * Sends file as a download to user.
  120. *
  121. * @param string $filename file name
  122. *
  123. * @return void
  124. */
  125. function Download($filename)
  126. {
  127. $pdfData = $this->getPDFData();
  128. PMA_Response::getInstance()->disable();
  129. PMA_downloadHeader($filename, 'application/pdf', strlen($pdfData));
  130. echo $pdfData;
  131. }
  132. }