Skip to content

Commit

Permalink
Pdf Writer strtoupper() fix (#1629)
Browse files Browse the repository at this point in the history
* _setPageSize's strtoupper()  on array argument

PhpSpreadsheet/Writer/Pdf.php Class defines a protected static mixed array called $paperSizes, this array contains string values along with array values. 'strtoupper() expects parameter 1 to be string, array given' error happens due to array passed to $paperSize variable from that $paperSizes mixed array on the Mpdf Class where Pdf extends

Examples of cases, when a 'Letter' paper size is chosen, then no problem occurs since the index in that value for the array is a string value, but when 'Tabloid' paper size is chosen the value in the index for that paper size is an array, that's when the strtoupper() error happens

* _setPageSize's strtoupper() on array argument

PhpSpreadsheet/Writer/Pdf.php Class defines a protected static mixed array called $paperSizes, this array contains string values along with array values. 'strtoupper() expects parameter 1 to be string, array given' error happens due to array passed to $paperSize variable from that $paperSizes mixed array on the Dompdf Class where Pdf extends

Examples of cases; when a 'Letter' paper size is chosen, then no problem occurs since the index in the array for that value a string, but when 'Tabloid' paper size is chosen the value in the index for that paper size is an array, that's when the strtoupper() error happens.
  • Loading branch information
adancabanas committed Feb 28, 2021
1 parent 1d6f36d commit 0715b63
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Pdf/Dompdf.php
Expand Up @@ -59,7 +59,7 @@ public function save($pFilename): void

// Create PDF
$pdf = $this->createExternalWriterInstance();
$pdf->setPaper(strtolower($paperSize), $orientation);
$pdf->setPaper($paperSize, $orientation);

$pdf->loadHtml($this->generateHTMLAll());
$pdf->render();
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Pdf/Mpdf.php
Expand Up @@ -64,7 +64,7 @@ public function save($pFilename): void
$config = ['tempDir' => $this->tempDir . '/mpdf'];
$pdf = $this->createExternalWriterInstance($config);
$ortmp = $orientation;
$pdf->_setPageSize(strtoupper($paperSize), $ortmp);
$pdf->_setPageSize($paperSize, $ortmp);
$pdf->DefOrientation = $orientation;
$pdf->AddPageByArray([
'orientation' => $orientation,
Expand Down

0 comments on commit 0715b63

Please sign in to comment.