8889841cPK‘«[gsÇ5ææ Tcpdf.phpnu„[µü¤setUseInlineCss(true); } /** * Gets the implementation of external PDF library that should be used. * * @param string $orientation Page orientation * @param string $unit Unit measure * @param array|string $paperSize Paper size * * @return \TCPDF implementation */ protected function createExternalWriterInstance($orientation, $unit, $paperSize) { return new \TCPDF($orientation, $unit, $paperSize); } /** * Save Spreadsheet to file. * * @param string $filename Name of the file to save as */ public function save($filename, int $flags = 0): void { $fileHandle = parent::prepareForSave($filename); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) // Check for paper size and page orientation if ($this->getSheetIndex() === null) { $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() == 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() == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); } // Override Page Orientation if ($this->getOrientation() !== null) { $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; } // Override Paper Size if ($this->getPaperSize() !== null) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$paperSizes[$printPaperSize])) { $paperSize = self::$paperSizes[$printPaperSize]; } // Create PDF $pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize); $pdf->setFontSubsetting(false); // Set margins, converting inches to points (using 72 dpi) $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72); $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AddPage(); // Set the appropriate font $pdf->SetFont($this->getFont()); $pdf->writeHTML($this->generateHTMLAll()); // 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()); // Write to file fwrite($fileHandle, $pdf->output($filename, 'S')); parent::restoreStateAfterSave(); } } PK‘«[Ý‚.I$$Mpdf.phpnu„[µü¤getSheetIndex()) { $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(); } $this->setOrientation($orientation); // Override Page Orientation if (null !== $this->getOrientation()) { $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_DEFAULT) ? 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 $config = ['tempDir' => $this->tempDir . '/mpdf']; $pdf = $this->createExternalWriterInstance($config); $ortmp = $orientation; $pdf->_setPageSize($paperSize, $ortmp); $pdf->DefOrientation = $orientation; $pdf->AddPageByArray([ 'orientation' => $orientation, 'margin-left' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getLeft()), 'margin-right' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getRight()), 'margin-top' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getTop()), 'margin-bottom' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getBottom()), ]); // 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()); $html = $this->generateHTMLAll(); foreach (\array_chunk(\explode(PHP_EOL, $html), 1000) as $lines) { $pdf->WriteHTML(\implode(PHP_EOL, $lines)); } // Write to file fwrite($fileHandle, $pdf->Output('', 'S')); parent::restoreStateAfterSave(); } /** * Convert inches to mm. * * @param float $inches * * @return float */ private function inchesToMm($inches) { return $inches * 25.4; } } PK‘«[LEjET T Dompdf.phpnu„[µü¤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($paperSize, $orientation); $pdf->loadHtml($this->generateHTMLAll()); $pdf->render(); // Write to file fwrite($fileHandle, $pdf->output()); parent::restoreStateAfterSave(); } } PK‘«[gsÇ5ææ Tcpdf.phpnu„[µü¤PK‘«[Ý‚.I$$Mpdf.phpnu„[µü¤PK‘«[LEjET T {Dompdf.phpnu„[µü¤PKÛ (