Setasign / FPDI

FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF.
https://www.setasign.com/fpdi
MIT License
1.09k stars 159 forks source link

Undefined array key "rect" Error in FpdiTrait.php #177

Closed okaufmann closed 1 year ago

okaufmann commented 1 year ago

Description: While running my project with FPDI version 2.4.0, I encountered an Undefined array key "rect" error. This error seems to be originating from the FpdiTrait.php file. Notably, this issue does not occur in version 2.3.7.

Error Message:

[2023-07-26 21:19:14] local.ERROR: Undefined array key "rect" {"exception":"[object] (ErrorException(code: 0): Undefined array key "rect" at [trimmed]/vendor/setasign/fpdi/src/FpdiTrait.php:485)

Environment:

JanSlabon commented 1 year ago

Please share the PDF in question and also a minimal reproducable code snipped, so that we can reproduce this. Thanks!

okaufmann commented 1 year ago

I generate it like this: (unfortunately I can not share the base PDF file. But it is a PDF (version 1.5).

$mpdf = new Mpdf([
       'fontDir' => ['fonts'],
       'fontdata' => ['volkart' => [
              'R' => 'volkart-regular/Volkart-Regular.ttf',
       ]],
       'default_font' => 'volkart',
]);

$mpdf->setSourceFile('my-pdf.pdf');

$mpdf->AddPage('P');
$templateId = $mpdf->importPage(1);
$mpdf->useTemplate($templateId);

$mpdf->WriteFixedPosHTML($this->html('a wonderful product', '#000'), 77.5, 85.3, 99, 15, 'auto');
$mpdf->WriteFixedPosHTML($this->html('a description', '#000'), 77.5, 126, 99, 15, 'auto');

// ...

protected function html(string $text, string $color)
{
       return <<<HTML
       <table style="width: 100%; margin: 0; padding: 0;" cellpadding="0" cellspacing="0">
       <tr>
              <td style="height: 47pt; text-align: center; vertical-align: middle; padding: 0px 5px; margin: 0; font-size: 35px; color: {$color}">
              {$text}
              </td>
       </tr>
       </table>
       HTML;
}
JanSlabon commented 1 year ago

Okay, there's a variable clash between FPDI and mPDF.

I just added a quick fix to the development branch. Can you please test it? If this works I am going to release a hotfix tomorrow morning. Gn8!

JanSlabon commented 1 year ago

Fixed in https://github.com/Setasign/FPDI/releases/tag/v2.4.1