laravel-dompdf icon indicating copy to clipboard operation
laravel-dompdf copied to clipboard

Streaming/downloading generated pdf that has been ->save()d before breaks the fonts

Open verybigelephants opened this issue 2 years ago • 1 comments

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 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.

Describe the bug Calling $pdf->save() before ->stream() or ->download() on a document with custom loaded external fonts break them in the streaming/downloading, but does not break them in the file stored via ->save()

To Reproduce Steps to reproduce the behavior:

using "barryvdh/laravel-dompdf": "^2.0", on laravel 10

  1. have this simple html:
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	
	<title>I am used for dompdf font size calculation.</title>
        <link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Trocchi&display=swap" rel="stylesheet">
</head>
<body>
     <span style="font-family:'Trocchi';">I have a custom font</span>
</body>
  1. load it, $pdf = Pdf::loadView('demo');
  2. render it return $file->stream(); - now you should see it with a proper font
  3. Now before doing the $file->stream(), save it to some random file, like $pdf->save( storage_path('demo.pdf'));
  4. Streamed file fonts are not working now, while the file that has been saved via ->save() has all correct fonts

Expected behavior fonts working

verybigelephants avatar Apr 26 '23 15:04 verybigelephants

Feel free to make a PR to fix that

parallels999 avatar Apr 27 '23 19:04 parallels999