PDF.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * @param boolean $pdfa If TRUE set the document to PDF/A mode.
  36. *
  37. * @access public
  38. */
  39. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4',
  40. $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa=false
  41. ) {
  42. parent::__construct(
  43. $orientation, $unit, $format, $unicode,
  44. $encoding, $diskcache, $pdfa
  45. );
  46. $this->SetAuthor('phpMyAdmin ' . PMA_VERSION);
  47. $this->AddFont('DejaVuSans', '', 'dejavusans.php');
  48. $this->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
  49. $this->SetFont(PMA_PDF_FONT, '', 14);
  50. $this->setFooterFont(array(PMA_PDF_FONT, '', 14));
  51. }
  52. /**
  53. * This function must be named "Footer" to work with the TCPDF library
  54. *
  55. * @return void
  56. */
  57. function Footer()
  58. {
  59. // Check if footer for this page already exists
  60. if (!isset($this->footerset[$this->page])) {
  61. $this->SetY(-15);
  62. $this->SetFont(PMA_PDF_FONT, '', 14);
  63. $this->Cell(
  64. 0, 6,
  65. __('Page number:') . ' '
  66. . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),
  67. 'T', 0, 'C'
  68. );
  69. $this->Cell(0, 6, PMA_Util::localisedDate(), 0, 1, 'R');
  70. $this->SetY(20);
  71. // set footerset
  72. $this->footerset[$this->page] = 1;
  73. }
  74. }
  75. /**
  76. * Function to set alias which will be expanded on page rendering.
  77. *
  78. * @param string $name name of the alias
  79. * @param string $value value of the alias
  80. *
  81. * @return void
  82. */
  83. function SetAlias($name, $value)
  84. {
  85. $name = TCPDF_FONTS::UTF8ToUTF16BE(
  86. $name, false, true, $this->CurrentFont
  87. );
  88. $this->Alias[$name] = TCPDF_FONTS::UTF8ToUTF16BE(
  89. $value, false, true, $this->CurrentFont
  90. );
  91. }
  92. /**
  93. * Improved with alias expanding.
  94. *
  95. * @return void
  96. */
  97. function _putpages()
  98. {
  99. if (count($this->Alias) > 0) {
  100. $nbPages = count($this->pages);
  101. for ($n = 1; $n <= $nbPages; $n++) {
  102. $this->pages[$n] = strtr($this->pages[$n], $this->Alias);
  103. }
  104. }
  105. parent::_putpages();
  106. }
  107. /**
  108. * Displays an error message
  109. *
  110. * @param string $error_message the error mesage
  111. *
  112. * @return void
  113. */
  114. function Error($error_message = '')
  115. {
  116. PMA_Message::error(
  117. __('Error while creating PDF:') . ' ' . $error_message
  118. )->display();
  119. exit;
  120. }
  121. /**
  122. * Sends file as a download to user.
  123. *
  124. * @param string $filename file name
  125. *
  126. * @return void
  127. */
  128. function Download($filename)
  129. {
  130. $pdfData = $this->getPDFData();
  131. PMA_Response::getInstance()->disable();
  132. PMA_downloadHeader($filename, 'application/pdf', strlen($pdfData));
  133. echo $pdfData;
  134. }
  135. }