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

AbdulBazith's avatar

Problem in conversion to pdf in Laravel

Guys I installed barryvdh/laravel-dompdf to convert html to pdf convertor for my report generation.

This is my controller



public function download()
{    
 $sales = Sales_details::all();

    $pdf=PDF::loadView('Sales_details.view1',['sales'=>$sales]);

    return $pdf->download('salesdetails1.pdf');
}

This is my view1.blade



<html>
    <head>
        <style>

            table{border-collapse:collapse;
            }

            td,th
            {
                border:1px solid;

            }
            </style>
    </head>
    <body>

        <caption><h2 align="center">SALES ENTRY PREVIEW</h2></caption><br>

    <table>

      <thead>
            <th>ID</th>
              <th>Date</th>
              <th>Time</th>
              {{-- <th>Customer Id</th> --}}
              <th>Customer Type</th>
              <th>Customer Name</th>
              {{-- {{-- <th>Customer Location</th> --}}
              <th>Customer Area</th>
              <th>Customer Booth</th>
              <th>Employee</th>
              <th>Rate/Litre</th>
              <th>No of Litres (Lt)</th>
              <th>Total (Rs)</th>
      </thead>

      <tbody>
        @foreach($sales as $sal)
        <tr>

            <td>{{ $sal->id }}</td>
            <td>{{ $sal->date }}</td>
            <td>{{ $sal->time }}</td>
            {{-- <td>{{ $sal->customer_id }}</td> --}}
            <td>{{ $sal->customer_type }}</td>
            <td>{{ $sal->customer_name }}</td>
            {{-- {{-- <td>{{ $sal->customer_location }}</td> --}}
            <td>{{ $sal->customer_area }}</td>
            <td>{{ $sal->customer_booth }}</td>
            <td>{{ $sal->emp }}</td>
            <td>{{ $sal->rate_per_litre }}</td>
            <td>{{ $sal->no_of_litre }}</td>
            <td>{{ $sal->total }}</td>

        </tr>
    @endforeach
      </tbody>
      </table>
    </body>

      </html>


My problem is the tables are not correctly fitted in the pdf.

This the output pdf

Refer : https://imgur.com/a/SIhsDMo

What’s the problem kindly help me solve this. The data are displayed in the side of the page why?

And kindly someone help to convert my database into excel also. I tried Maatwebsite. But the syntax are not accepted due to version problem. I installed new version that is above 3.

In YouTube all the videos related to maatwebsite is lower version. So that is also problem

i need to copy my db into excel sheet also. Kindly help

Kindly suggest me idea for that to please..

0 likes
9 replies
Tomi's avatar

Cant see any problem at first glance, i would add this to the start of the page:

<!DOCTYPE html>

and maybe start to debug when the table gets broken, start with showing only 1 row, then slowly build up the table.

1 like
AbdulBazith's avatar

@Tomi see the image i mentioned.. the next row is added in the side.. total is my last heading. but after the first record is displayed in the side. why that problem? is there any formatting

rule here..

1 like
Snapey's avatar

The first thing I spot is an in balance of comment tags

here

              {{-- {{-- <th>Customer Location</th> --}}

and here

        {{-- {{-- <td>{{ $sal->customer_location }}</td> --}}
1 like
Snapey's avatar
Snapey
Best Answer
Level 122

<th> also needs to be wrapped in <tr>

      <thead>
        <tr>
            <th>ID</th>
              <th>Date</th>
              <th>Time</th>
              {{-- <th>Customer Id</th> --}}
              <th>Customer Type</th>
              <th>Customer Name</th>
              {{-- <th>Customer Location</th> --}}
              <th>Customer Area</th>
              <th>Customer Booth</th>
              <th>Employee</th>
              <th>Rate/Litre</th>
              <th>No of Litres (Lt)</th>
              <th>Total (Rs)</th>
        </tr>
      </thead>
1 like
AbdulBazith's avatar

@Snapey Really u are genius.. thank you sooooo much, it worked.. thank youu

Kindly suggest an package please for my excel conversion also

please.. Need to export the data in excel sheet please please kindly suggest an idea

1 like
Snapey's avatar

Maatwebsite is the one to use. Suggest you post a new question with what you tried and what is happening.

1 like

Please or to participate in this conversation.