TCPDF.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * TCPDF writer
  21. *
  22. * @link http://www.tcpdf.org/
  23. * @since 0.11.0
  24. */
  25. class TCPDF extends AbstractRenderer implements WriterInterface
  26. {
  27. /**
  28. * Name of renderer include file
  29. *
  30. * @var string
  31. */
  32. protected $includeFile = 'tcpdf.php';
  33. /**
  34. * Save PhpWord to file.
  35. *
  36. * @param string $filename Name of the file to save as
  37. * @return vois
  38. */
  39. public function save($filename = null)
  40. {
  41. $fileHandle = parent::prepareForSave($filename);
  42. // PDF settings
  43. $paperSize = 'A4';
  44. $orientation = 'P';
  45. // Create PDF
  46. $pdf = new \TCPDF($orientation, 'pt', $paperSize);
  47. $pdf->setFontSubsetting(false);
  48. $pdf->setPrintHeader(false);
  49. $pdf->setPrintFooter(false);
  50. $pdf->addPage();
  51. $pdf->setFont($this->getFont());
  52. $pdf->writeHTML($this->getContent());
  53. // Write document properties
  54. $phpWord = $this->getPhpWord();
  55. $docProps = $phpWord->getDocInfo();
  56. $pdf->setTitle($docProps->getTitle());
  57. $pdf->setAuthor($docProps->getCreator());
  58. $pdf->setSubject($docProps->getSubject());
  59. $pdf->setKeywords($docProps->getKeywords());
  60. $pdf->setCreator($docProps->getCreator());
  61. // Write to file
  62. fwrite($fileHandle, $pdf->output($filename, 'S'));
  63. parent::restoreStateAfterSave($fileHandle);
  64. }
  65. }