5eea3177f837ed757440f758506251e6eccfa1b9.svn-base 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Writer_PDF
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Writer_PDF
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Writer_PDF
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Writer_PDF implements PHPExcel_Writer_IWriter
  35. {
  36. /**
  37. * The wrapper for the requested PDF rendering engine
  38. *
  39. * @var PHPExcel_Writer_PDF_Core
  40. */
  41. private $_renderer = NULL;
  42. /**
  43. * Instantiate a new renderer of the configured type within this container class
  44. *
  45. * @param PHPExcel $phpExcel PHPExcel object
  46. * @throws PHPExcel_Writer_Exception when PDF library is not configured
  47. */
  48. public function __construct(PHPExcel $phpExcel)
  49. {
  50. $pdfLibraryName = PHPExcel_Settings::getPdfRendererName();
  51. if (is_null($pdfLibraryName)) {
  52. throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
  53. }
  54. $pdfLibraryPath = PHPExcel_Settings::getPdfRendererPath();
  55. if (is_null($pdfLibraryName)) {
  56. throw new PHPExcel_Writer_Exception("PDF Rendering library path has not been defined.");
  57. }
  58. $includePath = str_replace('\\', '/', get_include_path());
  59. $rendererPath = str_replace('\\', '/', $pdfLibraryPath);
  60. if (strpos($rendererPath, $includePath) === false) {
  61. set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath);
  62. }
  63. $rendererName = 'PHPExcel_Writer_PDF_' . $pdfLibraryName;
  64. $this->_renderer = new $rendererName($phpExcel);
  65. }
  66. /**
  67. * Magic method to handle direct calls to the configured PDF renderer wrapper class.
  68. *
  69. * @param string $name Renderer library method name
  70. * @param mixed[] $arguments Array of arguments to pass to the renderer method
  71. * @return mixed Returned data from the PDF renderer wrapper method
  72. */
  73. public function __call($name, $arguments)
  74. {
  75. if ($this->_renderer === NULL) {
  76. throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
  77. }
  78. return call_user_func_array(array($this->_renderer, $name), $arguments);
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function save($pFilename = null)
  84. {
  85. $this->_renderer->save($pFilename);
  86. }
  87. }