getSheetIndex() === null) { $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); } else { $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); } $orientation = ($orientation == 'L') ? 'landscape' : 'portrait'; // Override Page Orientation if ($this->getOrientation() !== null) { $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_DEFAULT) ? PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } // Override Paper Size if ($this->getPaperSize() !== null) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$paperSizes[$printPaperSize])) { $paperSize = self::$paperSizes[$printPaperSize]; } // Create PDF $pdf = $this->createExternalWriterInstance(); $pdf->setPaper(strtolower($paperSize), $orientation); $pdf->loadHtml($this->generateHTMLAll()); $pdf->render(); // Write to file fwrite($fileHandle, $pdf->output()); parent::restoreStateAfterSave(); } }