barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.76k stars 976 forks source link

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

Open verybigelephants opened 1 year ago

verybigelephants commented 1 year ago

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>
  2. load it, $pdf = Pdf::loadView('demo');
  3. render it return $file->stream(); - now you should see it with a proper font
  4. Now before doing the $file->stream(), save it to some random file, like $pdf->save( storage_path('demo.pdf'));
  5. Streamed file fonts are not working now, while the file that has been saved via ->save() has all correct fonts

Expected behavior fonts working

parallels999 commented 1 year ago

Feel free to make a PR to fix that