From 98cd5e07bfabffd2c49b2554c921d7b2d86517d9 Mon Sep 17 00:00:00 2001 From: KacerCZ Date: Fri, 13 Oct 2017 09:08:55 +0200 Subject: [PATCH] Temporary directory is passed to mPDF (#248) Temporary directory set to PDF writer is passed to mPDF object in constructor. mPDF 7.0 changed temporary directory configuration from constant to constructor parameter. Without this change it is not possible to change default temporary directory. See: https://mpdf.github.io/installation-setup/folders-for-temporary-files.html --- src/PhpSpreadsheet/Helper/Sample.php | 6 ++++++ src/PhpSpreadsheet/Writer/Pdf/MPDF.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Helper/Sample.php b/src/PhpSpreadsheet/Helper/Sample.php index 1200db76..5b2c4685 100644 --- a/src/PhpSpreadsheet/Helper/Sample.php +++ b/src/PhpSpreadsheet/Helper/Sample.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Helper; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\IWriter; +use PhpOffice\PhpSpreadsheet\Writer\Pdf; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use RecursiveRegexIterator; @@ -118,6 +119,11 @@ class Sample foreach ($writers as $writerType) { $path = $this->getFilename($filename, mb_strtolower($writerType)); $writer = IOFactory::createWriter($spreadsheet, $writerType); + if ($writer instanceof Pdf) { + // PDF writer needs temporary directory + $tempDir = $this->getTemporaryFolder(); + $writer->setTempDir($tempDir); + } $callStartTime = microtime(true); $writer->save($path); $this->logWrite($writer, $path, $callStartTime); diff --git a/src/PhpSpreadsheet/Writer/Pdf/MPDF.php b/src/PhpSpreadsheet/Writer/Pdf/MPDF.php index d20ec3b6..c97197bb 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/MPDF.php +++ b/src/PhpSpreadsheet/Writer/Pdf/MPDF.php @@ -55,7 +55,8 @@ class MPDF extends Core implements IWriter } // Create PDF - $pdf = new \Mpdf\Mpdf(); + $config = ['tempDir' => $this->tempDir]; + $pdf = new \Mpdf\Mpdf($config); $ortmp = $orientation; $pdf->_setPageSize(strtoupper($paperSize), $ortmp); $pdf->DefOrientation = $orientation;