admin管理员组

文章数量:1390204

I have been exploring the Laravel pdf package and I am facing this issue where i want to have a separate header in the first page. There are two issues i am facing. If I can solve one of the issues, I will be able to achieve this:

  1. I am unable to hide the first page header. If I can achieve this, I can put the first page header in the main page content and make @page:first top margin at a minimum value.
  2. Use a separate header on the first page. I am unable to use a separate header on the first page, in the header() blade file I use. I am assuming that this is because there is no way php knows (AFAIK) on which page I am on.

Here are the header file i am working with

<style>
    header {
        margin-right: 2cm;
        margin-left: 2.5cm;
        margin-top: 1.5cm;
        text-align: center !important;
    }

    table {
        table-layout: fixed;
        width: 100%;
    }
    
    .first-page {
        display: none;
        font-size: 12px;
    }

    .other-pages {
        display: block;
        font-size: 12px;
    }

    @page:first {
        .first-page {
            display: block;
        }
    
        .other-pages {
            display: none;
        }
    }

</style>

<header>
    <div class="first-page">First page content</div>
    <div class="other-pages">Other pages content</div>
</header>

In the above file, I am trying to hide the div with class first-page in the other pages and div with other-pages in the first page. As in documentation of the package, I have to use CSS of header in the same file as the content. Do you guys have any idea why this is not working

I did try both the ways explained above. As i mentioned before, if I can solve one of the ways, I can achieve what I am trying to do.

本文标签: How to have a separate header in first page of pdf using spatie laravel pdf packageStack Overflow