PDF.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * PHPExcel_Writer_PDF
  4. *
  5. * Copyright (c) 2006 - 2015 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 - 2015 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. class PHPExcel_Writer_PDF implements PHPExcel_Writer_IWriter
  28. {
  29. /**
  30. * The wrapper for the requested PDF rendering engine
  31. *
  32. * @var PHPExcel_Writer_PDF_Core
  33. */
  34. private $renderer = null;
  35. /**
  36. * Instantiate a new renderer of the configured type within this container class
  37. *
  38. * @param PHPExcel $phpExcel PHPExcel object
  39. * @throws PHPExcel_Writer_Exception when PDF library is not configured
  40. */
  41. public function __construct(PHPExcel $phpExcel)
  42. {
  43. $pdfLibraryName = PHPExcel_Settings::getPdfRendererName();
  44. if (is_null($pdfLibraryName)) {
  45. throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
  46. }
  47. $pdfLibraryPath = PHPExcel_Settings::getPdfRendererPath();
  48. if (is_null($pdfLibraryName)) {
  49. throw new PHPExcel_Writer_Exception("PDF Rendering library path has not been defined.");
  50. }
  51. $includePath = str_replace('\\', '/', get_include_path());
  52. $rendererPath = str_replace('\\', '/', $pdfLibraryPath);
  53. if (strpos($rendererPath, $includePath) === false) {
  54. set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath);
  55. }
  56. $rendererName = 'PHPExcel_Writer_PDF_' . $pdfLibraryName;
  57. $this->renderer = new $rendererName($phpExcel);
  58. }
  59. /**
  60. * Magic method to handle direct calls to the configured PDF renderer wrapper class.
  61. *
  62. * @param string $name Renderer library method name
  63. * @param mixed[] $arguments Array of arguments to pass to the renderer method
  64. * @return mixed Returned data from the PDF renderer wrapper method
  65. */
  66. public function __call($name, $arguments)
  67. {
  68. if ($this->renderer === null) {
  69. throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
  70. }
  71. return call_user_func_array(array($this->renderer, $name), $arguments);
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function save($pFilename = null)
  77. {
  78. $this->renderer->save($pFilename);
  79. }
  80. }