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

AbdulBazith's avatar

barryvdh/laravel-dompdf convertor orientation problem and corrections in 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
4 replies
AbdulBazith's avatar
AbdulBazith
OP
Best Answer
Level 5

worked as per @Snapey 's answer

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

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

   {{-- {{-- <td>{{ $sal->customer_location }}</td> --}}

<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>

This is the corrections said by @Snapey and it worked

1 like
Snapey's avatar

What happened to my answer? Did you duplicate the question?

AbdulBazith's avatar

@Snapey yes .. no one replied to this thread.. so i made some changes in the question and posted as new question..

in that you answered..

Please or to participate in this conversation.