4

I am using laravel 5.2, The dompdf runs fine at localhost but when moved to AWS it keeps showing ErrorException in Cpdf.php line 3855: Undefined index:, in this line (3855) has font variable.

Sample code :

$html = "<h2>Hello</h2>";
PDF::setOptions(['dpi' => 150, 'defaultFont' => 'sans-serif']);
$pdf = PDF::loadHTML($html)->setPaper('a4', 'landscape');
return $pdf->download('pdfview.pdf');

I can not set 'currentFont' => 'sans-serif' at setOptions due to no options in barryvdh/laravel-dompdf. so how can I solve currentFont issue.

Localhost - Windows - Runs fine.

AWS - Linux - Error.

151291
  • 3,308
  • 7
  • 48
  • 81

2 Answers2

15

Error solved by delete dompdf_font_family_cache.php file from storage/fonts and let the renderer regenerate the cache.

151291
  • 3,308
  • 7
  • 48
  • 81
  • Depending on your Laravel version, this file can be at `public/fonts/dompdf_font_family_cache.php` . Look there and delete the file to solve the problem. – rboeg Jan 07 '21 at 06:50
  • Thanks. I also recommend to ignore files in "storage/fonts" on Git. Here's [how to implement gitignore files](https://stackoverflow.com/a/19757964/4494207). – ibnɘꟻ Oct 29 '21 at 08:58
0

I faced this issue on the Linux machine. The error shown was

Undefined index: application/third_party/dompdf/lib/fonts\Times-Roman

If you observe the Directory separator before the font name '\' is not compatible in Linux environment. This path separator is hardcoded in the dompdf_font_family_cache.php file found in ../dompdf/lib/fonts folder.

Open the file in the editor and replace '\' with '/'. Save the changes. The code will start working.

Pankaj Shinde
  • 107
  • 1
  • 5