Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbdulBazith's avatar

dividing columns with barryvdh/laravel-dompdf laravel

Guys i have a small problem in my old project milkfarm

i have installed barryvdh/laravel-dompdf package for downloading it as pdf for reports like purchase, sales etc

the pdf has only 3 columns tables, so what my client expecting is to divide the page into two columns,

so pages can be reduced.

for that what can i do??

before that what i have is in my controller

 $pdf=PDF::loadView('Purchase_details.viewallpdf', [
       
            'total_amount'=>$purchase_details->sum('total'),
            'time'=>$request->search_time,
            'fromdate'=>$request->search_fromdate,          
            'total_litre'=>$purchase_details->sum('no_of_litre')

        ]);
    }

       $pdf->setPaper('A4','portrait');
        return $pdf->download('Purchase Details.pdf');

my pdf.blade file


<head>
    <style type="text/css" media="all">
        #design {
            font-family: Serif;
            border-collapse: collapse;
            width: 100%;
        }

        #design td,
        #design th,
        #design thead {
            border: 1px solid #000;
            font-size: 12px;
        }


        * {
            margin: 2px;
            padding: 2px;
        }
    </style>
</head>



<table id="design">

        <thead>
            <tr>

                <th>Date</th>
                <th>Time</th>
                <th>R/L</th>
                <th>No.of.Lit(Lt)</th>
                <th>Total(Rs)</th>
                <th>Note</th>
            </tr>
        </thead>

        <tbody>
            @foreach($purs as $pur)
            <tr>

                <td>{{ $pur->date->format('d-m-y') }}</td>
                <td>{{ $pur->time }}</td>
                <td>{{ $pur->rate_per_litre }}</td>
                <td align="right">{{ $pur->no_of_litre }}</td>
                <td align="right">{{ $pur->total }}</td>
                <td>{{ $pur->note }}</td>
            </tr>
            @endforeach
          
        </tbody>
    </table>

this generates an output pdf as like this: https://imgur.com/uwHualg

in the above image, it has only 6 columns th. so what my client expecting is to reduce the table and need to print its continuation side itself.

i removed the width: 100%; in the tag style

so what happened is,

see this image: https://imgur.com/OLrRWFT

in the above image now it is reduced. the continuation of the table must be side to next column, the page must be dived into two columns.

Kindly some one help..

in a single page two columns with continuation data...

0 likes
4 replies
mvd's avatar

Hi @abdulbazith,

I'm not 100% sure but is this what you want?

<?php
$pursSplit = array_chunk($purs , round(count($purs) / 2));
?>
<table width="100%;border:0;">
    <tr>
        <td>
            <table id="design">

                <thead>
                <tr>

                    <th>Date</th>
                    <th>Time</th>
                    <th>R/L</th>
                    <th>No.of.Lit(Lt)</th>
                    <th>Total(Rs)</th>
                    <th>Note</th>
                </tr>
                </thead>

                <tbody>
                @foreach($pursSplit[0] as $pur)
                    <tr>

                        <td>{{ $pur->date->format('d-m-y') }}</td>
                        <td>{{ $pur->time }}</td>
                        <td>{{ $pur->rate_per_litre }}</td>
                        <td align="right">{{ $pur->no_of_litre }}</td>
                        <td align="right">{{ $pur->total }}</td>
                        <td>{{ $pur->note }}</td>
                    </tr>
                @endforeach

                </tbody>
            </table>
        </td>
        <td>
            <table id="design">

                <thead>
                <tr>

                    <th>Date</th>
                    <th>Time</th>
                    <th>R/L</th>
                    <th>No.of.Lit(Lt)</th>
                    <th>Total(Rs)</th>
                    <th>Note</th>
                </tr>
                </thead>

                <tbody>
                @foreach($pursSplit[1] as $pur)
                    <tr>

                        <td>{{ $pur->date->format('d-m-y') }}</td>
                        <td>{{ $pur->time }}</td>
                        <td>{{ $pur->rate_per_litre }}</td>
                        <td align="right">{{ $pur->no_of_litre }}</td>
                        <td align="right">{{ $pur->total }}</td>
                        <td>{{ $pur->note }}</td>
                    </tr>
                @endforeach

                </tbody>
            </table>
        </td>
    </tr>
</table>
AbdulBazith's avatar

@mvd thank you for you response.

i tired your code.

it shows error

array_chunk() expects parameter 1 to be array, object given 

mvd's avatar

@abdulbazith probably a collection i gues. Can you change

$pursSplit = array_chunk($purs , round(count($purs) / 2));

to

$pursSplit = $purs->chunk(round($purs->count() / 2));
AbdulBazith's avatar

@mvd . thank you so much for your response.

let me try and inform you.'

thank you for your help

Please or to participate in this conversation.