DomPDF.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\PDF;
  18. use PhpOffice\PhpWord\Writer\WriterInterface;
  19. /**
  20. * DomPDF writer
  21. *
  22. * @link https://github.com/dompdf/dompdf
  23. * @since 0.10.0
  24. */
  25. class DomPDF extends AbstractRenderer implements WriterInterface
  26. {
  27. /**
  28. * Name of renderer include file
  29. *
  30. * @var string
  31. */
  32. protected $includeFile = 'dompdf_config.inc.php';
  33. /**
  34. * Save PhpWord to file.
  35. *
  36. * @param string $filename Name of the file to save as
  37. * @return void
  38. */
  39. public function save($filename = null)
  40. {
  41. $fileHandle = parent::prepareForSave($filename);
  42. // PDF settings
  43. $paperSize = 'A4';
  44. $orientation = 'portrait';
  45. // Create PDF
  46. $pdf = new \DOMPDF();
  47. $pdf->set_paper(strtolower($paperSize), $orientation);
  48. $pdf->load_html($this->getContent());
  49. $pdf->render();
  50. // Write to file
  51. fwrite($fileHandle, $pdf->output());
  52. parent::restoreStateAfterSave($fileHandle);
  53. }
  54. }