Ingen beskrivning

PDF.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PhpWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Writer;
  18. use PhpOffice\PhpWord\Exception\Exception;
  19. use PhpOffice\PhpWord\PhpWord;
  20. use PhpOffice\PhpWord\Settings;
  21. /**
  22. * PDF Writer
  23. *
  24. * @since 0.10.0
  25. */
  26. class PDF
  27. {
  28. /**
  29. * The wrapper for the requested PDF rendering engine
  30. *
  31. * @var \PhpOffice\PhpWord\Writer\PDF\AbstractRenderer
  32. */
  33. private $renderer = null;
  34. /**
  35. * Instantiate a new renderer of the configured type within this container class
  36. *
  37. * @param \PhpOffice\PhpWord\PhpWord $phpWord
  38. * @throws \PhpOffice\PhpWord\Exception\Exception
  39. */
  40. public function __construct(PhpWord $phpWord)
  41. {
  42. $pdfLibraryName = Settings::getPdfRendererName();
  43. $pdfLibraryPath = Settings::getPdfRendererPath();
  44. if (is_null($pdfLibraryName) || is_null($pdfLibraryPath)) {
  45. throw new Exception("PDF rendering library or library path has not been defined.");
  46. }
  47. $includePath = str_replace('\\', '/', get_include_path());
  48. $rendererPath = str_replace('\\', '/', $pdfLibraryPath);
  49. if (strpos($rendererPath, $includePath) === false) {
  50. set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath);
  51. }
  52. $rendererName = get_class($this) . '\\' . $pdfLibraryName;
  53. $this->renderer = new $rendererName($phpWord);
  54. }
  55. /**
  56. * Magic method to handle direct calls to the configured PDF renderer wrapper class.
  57. *
  58. * @param string $name Renderer library method name
  59. * @param mixed[] $arguments Array of arguments to pass to the renderer method
  60. * @return mixed Returned data from the PDF renderer wrapper method
  61. */
  62. public function __call($name, $arguments)
  63. {
  64. // Note: Commented because all exceptions should already be catched by `__construct`
  65. // if ($this->renderer === null) {
  66. // throw new Exception("PDF Rendering library has not been defined.");
  67. // }
  68. return call_user_func_array(array($this->renderer, $name), $arguments);
  69. }
  70. }