getSheetIndex()) { $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins(); } else { $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); } $this->setOrientation($orientation); // Override Page Orientation if (null !== $this->getOrientation()) { $orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_DEFAULT) ? \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } $orientation = strtoupper($orientation); // Override Paper Size if (null !== $this->getPaperSize()) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$paperSizes[$printPaperSize])) { $paperSize = self::$paperSizes[$printPaperSize]; } // Create PDF $pdf = new \mPDF(); $ortmp = $orientation; $pdf->_setPageSize(strtoupper($paperSize), $ortmp); $pdf->DefOrientation = $orientation; $pdf->AddPage($orientation); // Document info $pdf->SetTitle($this->spreadsheet->getProperties()->getTitle()); $pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator()); $pdf->SetSubject($this->spreadsheet->getProperties()->getSubject()); $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords()); $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); $pdf->WriteHTML( $this->generateHTMLHeader(false) . $this->generateSheetData() . $this->generateHTMLFooter() ); // Write to file fwrite($fileHandle, $pdf->Output('', 'S')); parent::restoreStateAfterSave($fileHandle); } }