diff --git a/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php b/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php index fe5cfe25c6..94cbaffcb7 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php @@ -30,9 +30,15 @@ public function __construct(Spreadsheet $spreadsheet) */ protected function createExternalWriterInstance(string $orientation, string $unit, $paperSize): \TCPDF { + $this->defines(); + return new \TCPDF($orientation, $unit, $paperSize); } + protected function defines(): void + { + } + /** * Save Spreadsheet to file. * diff --git a/src/PhpSpreadsheet/Writer/Pdf/TcpdfNoDie.php b/src/PhpSpreadsheet/Writer/Pdf/TcpdfNoDie.php new file mode 100644 index 0000000000..070e52d043 --- /dev/null +++ b/src/PhpSpreadsheet/Writer/Pdf/TcpdfNoDie.php @@ -0,0 +1,27 @@ +spreadsheet = new Spreadsheet(); + } + + protected function tearDown(): void + { + unset($this->spreadsheet); + } + + // Separate processes because of global defined names + #[Attributes\RunInSeparateProcess] + #[Attributes\PreserveGlobalState(false)] + public function testExceptionRatherThanDie(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Could not include font definition file'); + $sheet = $this->spreadsheet->getActiveSheet(); + $sheet->setCellValue('A1', 'cell'); + $writer = new TcpdfNoDie($this->spreadsheet); + $writer->setFont('xyz'); + $writer->save('php://memory'); + } +}