spatie / laravel-pdf

Create PDF files in Laravel apps
https://spatie.be/docs/laravel-pdf
MIT License
675 stars 53 forks source link

[Bug]: header, footer not showing #177

Open hurycz opened 3 weeks ago

hurycz commented 3 weeks ago

What happened?

I can't see header and footer in my PDF.

Any idea? I can't find any solutions on internet...

How to reproduce the bug

My controller:

return Pdf::view('pdf.invoice', ['invoice' => $invoice])
                ->headerView('pdf.invoice.header')
                ->footerView('pdf.invoice.footer')
                ->format(Format::A4)
                ->name('invoice.pdf');

My pdf.invoice.blade.php

<style>
    {!! Vite::content('resources/css/invoice.css') !!}
</style>
<div>some pdf body</div>

My pdf.invoice.footer.blade.php

<style>
    footer {
        padding: 0.5rem;
        padding-top: 0.25rem;
    }

    footer div p {
        color: black;
        font-size: 16px;
    }

</style>

<footer>
    <div>
        <p>Page @pageNumber of @totalPages</p>
    </div>
</footer>

pdf.invoice.header is almost same...

PDF rendered OK, but header and footer is (maybe) under main content. I don't know. When i select all text, i see footer and header text.

image

Package Version

1.5.2

PHP Version

8.3

Laravel Version

11.20

Which operating systems does with happen with?

Windows, Linux

Notes

No response

kevin-netsrik commented 2 weeks ago

I have the same issue, header and footer not shown on the page.

hurycz commented 2 weeks ago

I found solutions (transparent background with margins) Documentation needs to be fixxed how to use header/footer.

return Pdf::view('pdf.invoice', ['invoice' => $invoice])
                ->withBrowsershot(function (Browsershot $browsershot) {
                    $browsershot->transparentBackground();
                })
                ->margins(14,0,14,0)
                ->headerView('pdf.invoice.header')
                ->footerView('pdf.invoice.footer')
                ->format(Format::A4)
                ->name('invoice.pdf')
                ->save(storage_path("invoice.pdf"));
gabriellara181999 commented 2 weeks ago

tengo el mismo problema pero no me funciona