You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue when trying to insert a font into my PDF using TCPDF. The following code results in an error:
$pdf->font->insert($pdf->pon, 'helvetica', '', 10, 2, 2, $this->getParameter('k_path_fonts') . "/helvetica.json");
The error message is as follows:
Uncaught PHP Exception ErrorException: "Warning: Undefined array key 1" at Stack.php line 583
Upon reviewing the Stack.php file, I found that the issue is related to the code in lines 579–588, which deals with assigning the font bounding box values:
$this->metric[$mkey]['fbbox'] = [
// left
((float) $tbox[0] * $wratio),
// bottom
((float) $tbox[1] * $cratio),
// right
((float) $tbox[2] * $wratio),
// top
((float) $tbox[3] * $cratio),
];
The problem is that in my case, the $tbox array only contains tbox[0], and tbox[1] is missing, causing the undefined key error.
As a workaround, I modified the code to use the null coalescing operator (??) to provide default values in case any of the indices are missing:
$this->metric[$mkey]['fbbox'] = [
((float) ($tbox[0] ?? 0) * $wratio),
((float) ($tbox[1] ?? 0) * $cratio),
((float) ($tbox[2] ?? 0) * $wratio),
((float) ($tbox[3] ?? 0) * $cratio),
];
This approach resolved the issue for me. However, I am unsure if this is the best solution or if a more appropriate fix should be applied.
Could you please advise on whether this is a suitable fix, or if there might be a deeper issue with the $tbox array that needs to be addressed?
Best regards,
Diar
The text was updated successfully, but these errors were encountered:
Hello,
I encountered an issue when trying to insert a font into my PDF using TCPDF. The following code results in an error:
$pdf->font->insert($pdf->pon, 'helvetica', '', 10, 2, 2, $this->getParameter('k_path_fonts') . "/helvetica.json");
The error message is as follows:
Uncaught PHP Exception ErrorException: "Warning: Undefined array key 1" at Stack.php line 583
Upon reviewing the Stack.php file, I found that the issue is related to the code in lines 579–588, which deals with assigning the font bounding box values:
$this->metric[$mkey]['fbbox'] = [
// left
((float) $tbox[0] * $wratio),
// bottom
((float) $tbox[1] * $cratio),
// right
((float) $tbox[2] * $wratio),
// top
((float) $tbox[3] * $cratio),
];
The problem is that in my case, the $tbox array only contains tbox[0], and tbox[1] is missing, causing the undefined key error.
As a workaround, I modified the code to use the null coalescing operator (??) to provide default values in case any of the indices are missing:
$this->metric[$mkey]['fbbox'] = [
((float) ($tbox[0] ?? 0) * $wratio),
((float) ($tbox[1] ?? 0) * $cratio),
((float) ($tbox[2] ?? 0) * $wratio),
((float) ($tbox[3] ?? 0) * $cratio),
];
This approach resolved the issue for me. However, I am unsure if this is the best solution or if a more appropriate fix should be applied.
Could you please advise on whether this is a suitable fix, or if there might be a deeper issue with the $tbox array that needs to be addressed?
Best regards,
Diar
The text was updated successfully, but these errors were encountered: