PDF.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_Writer_PDF implements PHPExcel_Writer_IWriter
  8. {
  9. /**
  10. * The wrapper for the requested PDF rendering engine
  11. *
  12. * @var PHPExcel_Writer_PDF_Core
  13. */
  14. private $renderer = null;
  15. /**
  16. * Instantiate a new renderer of the configured type within this container class
  17. *
  18. * @param PHPExcel $phpExcel PHPExcel object
  19. * @throws PHPExcel_Writer_Exception when PDF library is not configured
  20. */
  21. public function __construct(PHPExcel $phpExcel)
  22. {
  23. $pdfLibraryName = PHPExcel_Settings::getPdfRendererName();
  24. if (is_null($pdfLibraryName)) {
  25. throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
  26. }
  27. $pdfLibraryPath = PHPExcel_Settings::getPdfRendererPath();
  28. if (is_null($pdfLibraryName)) {
  29. throw new PHPExcel_Writer_Exception("PDF Rendering library path has not been defined.");
  30. }
  31. $includePath = str_replace('\\', '/', get_include_path());
  32. $rendererPath = str_replace('\\', '/', $pdfLibraryPath);
  33. if (strpos($rendererPath, $includePath) === false) {
  34. set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath);
  35. }
  36. $rendererName = 'PHPExcel_Writer_PDF_' . $pdfLibraryName;
  37. $this->renderer = new $rendererName($phpExcel);
  38. }
  39. /**
  40. * Magic method to handle direct calls to the configured PDF renderer wrapper class.
  41. *
  42. * @param string $name Renderer library method name
  43. * @param mixed[] $arguments Array of arguments to pass to the renderer method
  44. * @return mixed Returned data from the PDF renderer wrapper method
  45. */
  46. public function __call($name, $arguments)
  47. {
  48. if ($this->renderer === null) {
  49. throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
  50. }
  51. return call_user_func_array(array($this->renderer, $name), $arguments);
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function save($pFilename = null)
  57. {
  58. $this->renderer->save($pFilename);
  59. }
  60. }