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
This commit is contained in:
KacerCZ 2017-10-13 09:08:55 +02:00 committed by Adrien Crivelli
parent add064e80e
commit 98cd5e07bf
2 changed files with 8 additions and 1 deletions

View File

@ -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);

View File

@ -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;