123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- $pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/mpdf.php';
- if (file_exists($pdfRendererClassFile)) {
- require_once $pdfRendererClassFile;
- } else {
- throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
- }
- class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
- {
-
- public function __construct(PHPExcel $phpExcel)
- {
- parent::__construct($phpExcel);
- }
-
- public function save($pFilename = null)
- {
- $fileHandle = parent::prepareForSave($pFilename);
-
- $paperSize = 'LETTER';
-
- if (is_null($this->getSheetIndex())) {
- $orientation = ($this->phpExcel->getSheet(0)->getPageSetup()->getOrientation()
- == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
- $printPaperSize = $this->phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
- $printMargins = $this->phpExcel->getSheet(0)->getPageMargins();
- } else {
- $orientation = ($this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
- == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
- $printPaperSize = $this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
- $printMargins = $this->phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
- }
- $this->setOrientation($orientation);
-
- if (!is_null($this->getOrientation())) {
- $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
- ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT
- : $this->getOrientation();
- }
- $orientation = strtoupper($orientation);
-
- if (!is_null($this->getPaperSize())) {
- $printPaperSize = $this->getPaperSize();
- }
- if (isset(self::$paperSizes[$printPaperSize])) {
- $paperSize = self::$paperSizes[$printPaperSize];
- }
-
- $pdf = new mpdf();
- $ortmp = $orientation;
- $pdf->_setPageSize(strtoupper($paperSize), $ortmp);
- $pdf->DefOrientation = $orientation;
- $pdf->AddPage($orientation);
-
- $pdf->SetTitle($this->phpExcel->getProperties()->getTitle());
- $pdf->SetAuthor($this->phpExcel->getProperties()->getCreator());
- $pdf->SetSubject($this->phpExcel->getProperties()->getSubject());
- $pdf->SetKeywords($this->phpExcel->getProperties()->getKeywords());
- $pdf->SetCreator($this->phpExcel->getProperties()->getCreator());
- $pdf->WriteHTML(
- $this->generateHTMLHeader(false) .
- $this->generateSheetData() .
- $this->generateHTMLFooter()
- );
-
- fwrite($fileHandle, $pdf->Output('', 'S'));
- parent::restoreStateAfterSave($fileHandle);
- }
- }
|