Skip to content

Output PDF Data Are Not Showing Properly, Aligned Right. #1056

@Moix1

Description

@Moix1

My Codes

This Page/View Receiving Data

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>PDF Report</title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <style>
        html, body {
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
        }
        .container {
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .table {
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="text-center mb-4">Shipment Report</h1>
        <div class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Waybill No</th>
                        <th>Tracking No</th>
                        <th>Destination</th>
                        <th>Packages</th>
                        <th>Total Weight</th>
                        <th>Volumetric Weight</th>
                        <th>Total Charges</th>
                        <th>Shipment Type</th>
                        <th>Service Type</th>
                        <th>Receiver Name</th>
                        <th>Extra Charges</th>
                        <th>Remark</th>
                        <th>Debit</th>
                        <th>Credit</th>
                        <th>Total Balance</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($data as $item)
                        <tr>
                            <td>{{ $item['date'] }}</td>
                            <td>{{ $item['waybill_no'] }}</td>
                            <td>{{ $item['tracking_no'] }}</td>
                            <td>{{ $item['destination'] }}</td>
                            <td>{{ $item['packages'] }}</td>
                            <td>{{ $item['total_weight'] }}</td>
                            <td>{{ $item['volumetric_weight'] }}</td>
                            <td>{{ $item['total_charges'] }}</td>
                            <td>{{ $item['shipment_type'] }}</td>
                            <td>{{ $item['service_type'] }}</td>
                            <td>{{ $item['receiver_name'] }}</td>
                            <td>{{ $item['extra_charges'] }}</td>
                            <td>{{ $item['remark'] }}</td>
                            <td>{{ $item['debit'] }}</td>
                            <td>{{ $item['credit'] }}</td>
                            <td>{{ $item['total_balance'] }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

My Function in Controller:

public function generatePDFReport()
    {
        // Fetch data from shipments and ledgers tables
        $shipments = Shipment::all(); // Adjust as per your filtering needs
        $data = [];

        foreach ($shipments as $shipment) {
            $ledger = Ledger::where('shipment_id', $shipment->id)->first();
            $volumetricWeight = $shipment->volume_piece1 + $shipment->volume_piece2;

            $data[] = [
                'date' => $shipment->created_at,
                'waybill_no' => $shipment->waybill_no,
                'tracking_no' => $shipment->tracking_no,
                'destination' => $shipment->receiver_country,
                'packages' => $shipment->total_pieces,
                'total_weight' => $shipment->total_weight,
                'volumetric_weight' => $volumetricWeight,
                'total_charges' => $shipment->final_charges,
                'shipment_type' => $shipment->package_type,
                'service_type' => $shipment->service_type,
                'receiver_name' => $shipment->receiver_name,
                'extra_charges' => $shipment->extra_charges,
                'remark' => $shipment->remark,
                'debit' => $ledger ? $ledger->debit : '',
                'credit' => $ledger ? $ledger->credit : '',
                'total_balance' => $ledger ? $ledger->balance : '',
            ];
        }

        // Generate PDF using Dompdf via the PDF facade
        $pdf = Pdf::loadView('admin.shipments.pdf_report', compact('data'))
                ->setPaper('A4', 'landscape');

        // Return PDF as a response
        return $pdf->download('shipment_report.pdf');
    }

This is how it showing. Cutting right side data.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions