What’s the best way to add a coverpage for a pdf made via browsershot / puppeteer?

15 Views Asked by At

So I am generating a pdf via spatie's browsershot package.

So far pretty simple

class CreatePdf
{
    public function __invoke(): PdfBuilder|View
    {
        $plan = Plan::with('propertyPartner')->find(request()->get('plan') ?? 1);

        return pdf()
            ->view('plans::pdf', ['data' => $plan])
            ->headerView('plans::includes.header', ['data' => $plan])
            ->footerView('plans::includes.footer')
            ->format(Format::A4)
            ->name('invoice-2023-04-10.pdf');
    }
}

everything works well, however, I need to add a cover page.

So I have done this and added the following CSS to hide the headers and footers

@page :first {
  margin-top: 0;
  margin-bottom: 0;
}

Again, this works great.

However, the paging is now off.

Here is my footer

<style>
    .pdf-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 0 20px;
    }

    .pdf-footer .svg-holder {
        width: 18px;
    }

    .pdf-footer svg {
        width: 100%;
        display: block;
    }

    .pdf-footer .page-count {
        font-size: 12px;
        line-height: 18px;
        color: rgb(51 51 51);
    }
</style>
<footer class="pdf-footer">
    <div class="svg-holder">
        <svg viewBox="0 0 12 12">
            <path d="M5.489 0C2.583.25 0 2.674 0 5.924c0 3.25 2.583 5.674 5.489 5.923-1.887-.486-3.596-2.727-3.89-5.072a6.383 6.383 0 0 1 0-1.703C1.896 2.72 3.595.504 5.49 0M6.511 0C9.417.25 12 2.674 12 5.924c0 3.25-2.583 5.674-5.489 5.923 1.887-.486 3.596-2.727 3.89-5.072a6.386 6.386 0 0 0 0-1.703C10.104 2.72 8.405.504 6.51 0Z" />
        </svg>
    </div>
    <aside class="page-count">@pageNumber/@totalPages</aside>
</footer>

The footer renders how I want it, however, it includes the cover page in the page count.

So how do I;

  1. Adjust the paging so it doesn't include the cover page or;
  2. Add a cover page (without merging pdfs) with it excluded in the page count
0

There are 0 best solutions below