Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/PhpSpreadsheet/Writer/Pdf/Mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function save($filename, int $flags = 0): void

// Create PDF
$config = ['tempDir' => $this->tempDir . '/mpdf'];
$restoreHandler = false;
if (PHP_VERSION_ID >= self::$temporaryVersionCheck) {
// @codeCoverageIgnoreStart
set_error_handler(self::specialErrorHandler(...));
$restoreHandler = true;
// @codeCoverageIgnoreEnd
}
$pdf = $this->createExternalWriterInstance($config);
$ortmp = $orientation;
$pdf->_setPageSize($paperSize, $ortmp);
Expand Down Expand Up @@ -83,9 +90,30 @@ public function save($filename, int $flags = 0): void
$str = $pdf->Output('', 'S');
fwrite($fileHandle, $str);

if ($restoreHandler) {
restore_error_handler(); // @codeCoverageIgnore
}
parent::restoreStateAfterSave();
}

protected static int $temporaryVersionCheck = 80600;

/**
* Temporary handler for Php8.6 mb_regex_encoding deprecation.
*
* @codeCoverageIgnore
*/
public function specialErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
{
if ($errno === E_DEPRECATED) {
if (preg_match('/Function mb_\w+[(][)] is deprecated since 8[.]6/', $errstr) === 1) {
return true;
}
}

return false; // continue error handling
}

/**
* Convert inches to mm.
*/
Expand Down
Loading