mccarlosen / laravel-mpdf

Generate PDFs in Laravel with Mpdf.
402 stars 107 forks source link

How to add style to header? #113

Closed realtebo closed 1 year ago

realtebo commented 1 year ago

I added an header into blade

<htmlpageheader name="page-header">
    <h3>RIEPILOGO
        <br/>
        Dal {{ $date_from->format('d/m/Y') }} al {{ $date_to->format('d/m/Y') }}
    </h3>
</htmlpageheader>

Then I added @page to css

    @page {
        header: page-header;
    }

I need to add a margin-top to my header.

How can I do this?

mccarlosen commented 1 year ago

Hi, you may view the documentation about the topic: Headers & Top margins

realtebo commented 1 year ago

Sorry, but the page doesn't help me to understand how to use your package to set these options into inner mPdf.

mccarlosen commented 1 year ago

It's like working with HTML and CSS.

All right! I explain to you:

You may write the next code in your blade template:

<!-- view.blade.php -->

<style>
@page {
    header: page-header;
    margin-top: 2cm;
    margin-header: 10mm; /* distance in mm from top of page to start of header */
}
</style>

<htmlpageheader name="page-header">
    <h3>RIEPILOGO
        <br/>
        Dal {{ $date_from->format('d/m/Y') }} al {{ $date_to->format('d/m/Y') }}
    </h3>
</htmlpageheader>

All CSS styles have to be into the blade view, wrap by <style></style> tags.

You can review for more information about @page support here.

I hope to help you!