Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Moix1 opened this issue Jun 27, 2024 · 2 comments
Open

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

Moix1 opened this issue Jun 27, 2024 · 2 comments

Comments

@Moix1
Copy link

Moix1 commented Jun 27, 2024

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

@parallels999
Copy link

**This is just a Dompdf wrapper!**
I understand that this package is just a Laravel wrapper for https://github.com/dompdf/dompdf
Any issues with PDF rendering, CSS that is not applied correctly, aligning/fonts/characters etc that are not directly related to this package, should be reported there. When having doubts, please try to reproduce the issue with just dompdf. If it's also present there, do not open an issue here please.

This is just a Dompdf wrapper!
I understand that this package is just a Laravel wrapper for https://github.com/dompdf/dompdf
Any issues with PDF rendering, CSS that is not applied correctly, aligning/fonts/characters/images/html etc that are not directly related to this package, should be reported there. When having doubts, please try to reproduce the issue with just dompdf. If it's also present there, do not open an issue here please.

@daptontdev1
Copy link

It would help if you used prop @page then will be working.

<style> /** Define the margins of your page **/ @page { margin: 140px 25px 50px 25px; } </style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants