barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.57k stars 965 forks source link

Undefined array key "" #1031

Open nemanja-ivanis opened 5 months ago

nemanja-ivanis commented 5 months ago

When i try to output my pdf i get "Undefined array key ''" on line 4752 in dompdf\dompdf\lib\Cpdf.php. That particular line of code is:

$font = $this->fonts[$this->currentFont];

Both $this->fonts and $this->currentFont are empty. Why is this happening and how can i fix it? Why are those arrays and variables empty? It seems like a problem with the package.

I am using laravel 10.10 and barryvdh/laravel-dompdf 2.0.1.

parallels999 commented 5 months ago

https://github.com/barryvdh/laravel-dompdf/blob/424a223ce80e7afc8bfb6e84449679efe272fbb5/.github/ISSUE_TEMPLATE/bug_report.md?plain=1#L10-L12

This is just a Dompdf wrapper! I understand that this package is just a Laravel wrapper for https://github.com/dompdf/dompdf Any issues with PDF rendering, CSS that is not applied correctly, aligning/fonts/characters/images/html etc that are not directly related to this package, should be reported there. When having doubts, please try to reproduce the issue with just dompdf. If it's also present there, do not open an issue here please.

worktchaloemphon commented 2 months ago

I got this error too.

and here is my code.

` $domPdf = $pdf->getDomPDF(); $canvas = $domPdf->get_canvas(); $font = $domPdf->getFontMetrics()->get_font("thsarabun", "normal"); // get null because there are not cached in storage/fonts

// comment here to cache fonts file $canvas->page_text( $x = $canvas->get_width() - 80, $y = $canvas->get_height() - 40, $text = "Page Number {PAGE_NUM} of {PAGE_COUNT}", $font = $font, $size = 15, $color = array(0, 0, 0) );

return $pdf->stream('example.pdf');

`

I have already put my fonts file .ttf to storage/fonts but Laravel doesn't cache it into .ufm file. so I comment line $canvas->page_text() and run only return $pdf-stream(). It start to generate cache fonts file inside storage/fonts

So I uncomment $canvas->page_text() and It work. It ref pic is my final files inside storage/fonts

Screenshot 2567-05-13 at 23 21 44

( sorry for my English.)