Laravel Blade Foreach Loop In Laravel-DOMPDF Output File

- 1 answer

I'm having issues using DOMPDF and Laravel Blade. I'm using DOMPDF to render a blade view into PDF following their documentation, but when I have records that span more than a page, it cuts them off. It's like overflow:hidden is added to the page so the records won't show. You can see by the image below. You can clearly see there is another record at the bottom, but the next page is qualifications, not the next record in the list.

I have tried using page breaks and all sorts to try and get this working, but for the life of me this just does not want to play ball.

I can't find anything in their documentation that suggests this is an issue and I'm not sure what's causing it.

Package used: barryvdh/laravel-dompdf

The rendered PDF:

enter image description here

The section of the view that's being loaded:

Please excuse the tables, but as PDFs don't load CSS3, I have to go back to basics to get the proper styling results needed for the PDF.

    <td class="border-b-4 border-grey-200 pb-5 mb-5">
        <table width="100%" class="mb-5" style="width:100%" border="0" cellpadding="0">
                    <h1 class="text-6 text-grey-700 mb-3">Employment History</h1>
        @foreach ($employers as $employer)
        <table width="100%" class="mb-5" style="width:100%" border="0" cellpadding="0">
                <td class="border border-grey-200 p-5 rounded">
                    <h2 class="capitalize text-grey-700 text-lg">{{ $employer->job_title }}</h2>
                    <span class="text-grey-600">{{ $employer->employer_name }}</span>
                    <p class="my-3 text-blue-500 text-sm">
                        <span>{{ date('jS F Y', strtotime($employer->from_date)) }}</span>
                        <span> — </span>
                        @if ($employer->current != 1)
                            <span>{{ date('jS F Y', strtotime($employer->to_date)) }}</span>
                    <div class="markdown text-grey-700">{!! $employer->description !!}</div>

The PDF controller:

    'dpi' => 150,
    'defaultFont' => 'sans-serif',
    'fontHeightRatio' => 1,
    'isPhpEnabled' => true,

$pdf = PDF::loadView('pdf_cv', [
    'cv' => $cv,
    'awards' => $awards,
    'employers' => $employers,
    'hobbies' => $hobbies,
    'images' => $images,
    'languages' => $languages,
    'projects' => $projects,
    'qualifications' => $qualifications,
    'skills' => $skills

return $pdf->stream();

I've done the Googling, read their documentation countless times and I'm bemused by this issue, so hopefully, someone else has experienced this too and can lend a helping hand.

If you need more information, I can provide it.



The issue with this was the table setup. I don't know exactly what was happening because you can't inspect PDFs but the table seemed to keep overlapping causing it run off the page.