TCPDF.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * @see https://github.com/PHPOffice/PhpWord
  14. * @copyright 2010-2018 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. * @deprecated 0.13.0 Use `DomPDF` or `MPDF` instead.
  23. *
  24. * @see http://www.tcpdf.org/
  25. * @since 0.11.0
  26. */
  27. class TCPDF extends AbstractRenderer implements WriterInterface
  28. {
  29. /**
  30. * Name of renderer include file
  31. *
  32. * @var string
  33. */
  34. protected $includeFile = 'tcpdf.php';
  35. /**
  36. * Gets the implementation of external PDF library that should be used.
  37. *
  38. * @param string $orientation Page orientation
  39. * @param string $unit Unit measure
  40. * @param string $paperSize Paper size
  41. *
  42. * @return \TCPDF implementation
  43. */
  44. protected function createExternalWriterInstance($orientation, $unit, $paperSize)
  45. {
  46. return new \TCPDF($orientation, $unit, $paperSize);
  47. }
  48. /**
  49. * Save PhpWord to file.
  50. *
  51. * @param string $filename Name of the file to save as
  52. */
  53. public function save($filename = null)
  54. {
  55. $fileHandle = parent::prepareForSave($filename);
  56. // PDF settings
  57. $paperSize = 'A4';
  58. $orientation = 'P';
  59. // Create PDF
  60. $pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize);
  61. $pdf->setFontSubsetting(false);
  62. $pdf->setPrintHeader(false);
  63. $pdf->setPrintFooter(false);
  64. $pdf->AddPage();
  65. $pdf->SetFont($this->getFont());
  66. $pdf->writeHTML($this->getContent());
  67. // Write document properties
  68. $phpWord = $this->getPhpWord();
  69. $docProps = $phpWord->getDocInfo();
  70. $pdf->SetTitle($docProps->getTitle());
  71. $pdf->SetAuthor($docProps->getCreator());
  72. $pdf->SetSubject($docProps->getSubject());
  73. $pdf->SetKeywords($docProps->getKeywords());
  74. $pdf->SetCreator($docProps->getCreator());
  75. // Write to file
  76. fwrite($fileHandle, $pdf->Output($filename, 'S'));
  77. parent::restoreStateAfterSave($fileHandle);
  78. }
  79. }