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;