jeudi 16 janvier 2020

Generate PDF in Laravel and barryvdh/laravel-dompdf - problem with table

I am beginner in Laravel. I use in my project Laravel 5.8 and barryvdh/laravel-dompdf.

I have this blade file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Wydruk</title>
    @stack('styles')
    <style type="text/css">
        @page {
            margin: 30px 30px;
            margin-bottom: 40px;
        }

        /*#header { position: fixed; left: 0px; top: -220px; right: 0px; height: 205px; text-align: center; border-bottom: 1px solid lightgrey;}*/

        body {
            font-family: DejaVu Sans;
            font-style: normal;
            font-weight: 400;
            font-size: 16px;
        }

        .logo {
            height: 125px;
        }

        .fontSize19 {
            font-size: 19px;
        }

        .fontSize9 {
            font-size: 9px;
        }

        .fontSize22 {
            font-size: 22px;
        }

        .fontSize25 {
            font-size: 25px;
        }

        .page-break {
            page-break-after: always;
        }

        .fontNormal {
            font-weight: normal;
            font-family: DejaVu Sans;
            font-style: normal;
            font-size: 16px;
        }

        table {
            border-collapse: collapse;
            border-spacing: 2px;
        }

        table, th, td {
            border: 1px solid black;
        }

        td, th {
            padding: 6px;
        }
        /*table thead {*/
        /*    display: table-row-group;*/
        /*}*/

    </style>
</head>

<body>
<script type="text/php">
    if ( isset($pdf) ) {
        $x = 770;
        $y = 570;
        $text = "Strona {PAGE_NUM} z {PAGE_COUNT}";
        $font = $fontMetrics->get_font("DejaVu Sans", "normal");
        $size = 6;
        $color = array(0,0,0);
        $word_space = 0.0;
        $char_space = 0.0;
        $angle = 0.0;
        $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);

        $x = 25;
        $y = 570;
        $text = "@ ".env('APP_NAME'). ". Wszystkie prawa zastrzeżone. Data wydruku: ". date('Y-m-d H:i:s');
        $font = $fontMetrics->get_font("DejaVu Sans", "normal");
        $size = 6;
        $color = array(0,0,0);
        $word_space = 0.0;
        $char_space = 0.0;
        $angle = 0.0;
        $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
    }


</script>


@php

    function getPolishDayName(string $name): string
    {
        if($name == "Monday"){
            return "Poniedziałek";
        } elseif ($name == "Tuesday"){
            return "Wtorek";
        } elseif ($name == "Wednesday"){
            return "Środa";
        } elseif ($name == "Thursday"){
            return "Czwartek";
        } elseif ($name == "Friday"){
            return "Piątek";
        } elseif ($name == "Saturday"){
            return "Sobota";
        } elseif ($name == "Sunday"){
            return "Niedziela";
        }
    }
@endphp

<div id="content" class="fontSize11">
    <b class="fontSize22">Jadłospis </b><br/><br/>


    <table width="100%">
        <thead style="background-color: lightgray;">
        <tr>
            <th width="10%" align="center" scope="col"><b>DZIEŃ TYGODNIA</b></th>
            <th width="18%" align="center" scope="col"><b>NAZWA POTRAWY</b><br/>
                przybliżona minimalna gramatura po obróbce (g),(nie obejmuje sosów)
            </th>
            <th width="18%" align="center" scope="col"><b>NAZWA PRODUKTU</b></th>
            <th width="18%" align="center" scope="col"><b>ILOŚĆ</b><br/>surowca na porcję (przed obróbką) [g]</th>
        </tr>
        </thead>


        @php
            Illuminate\Support\Carbon::setLocale('pl');
            $period = Carbon\CarbonPeriod::create($nutritionPlan->date_from, $nutritionPlan->date_to);
        @endphp

        @foreach ($period as $date) 
        <tr>
            <td width="15.61%" rowspan="5"
                class="fontNormal" align="center">
                <br/></td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa potrawy 1'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa produktu'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'ilośc 1'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
        </tr>
        <tr>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa potrawy 2'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa produktu 2'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'ilośc 2'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
        </tr>
        <tr>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa potrawy 3'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa produktu 3'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'ilośc 3'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
        </tr>
        <tr>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa potrawy 4'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa produktu 4'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'ilośc 4'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
        </tr>
        <tr>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa potrawy 5'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'nazwa produktu 5'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
            <td width="33.33%" class="fontNormal td2 tdBorderRight tdBorderBottom">
                <div class="tablePadding">
                    @foreach($nutritionPlan->items as $value)
                        @if($value->meal_type == 1 and $value->date == $date->format('Y-m-d'))
                            @php echo 'ilośc 5'; @endphp,<br/>
                        @endif
                    @endforeach
                </div>
            </td>
        </tr>
        @endforeach

    </table>


</div>



</body>
</html>

And this is my php function to generate PDF:

$logo = public_path('assets/images/logo_print.jpg');
        $pdf = \PDF::loadView('psCMS.prints.raport2', ['nutritionPlan' => $nutritionPlan, 'logo' => $logo]);
        $pdf->setOptions(['isPhpEnabled' => true, 'dpi' => 150, 'setIsRemoteEnabled' => true]);
        $pdf->setPaper('A4', 'landscape'); // letter
        return $pdf->download('Raport' . '-' . now()->toDateString() . '.pdf');

It's work fine. I have PDF with my data.

Problem is when my table has more that 1 page: https://ibb.co/4sMpSV9 Monday = Monday. The day of the week should still be on the 2nd page in the 1st column, and the other columns should be shifted to the right.

They should look similar to the top.

Anyone know how to fix this?

Please help. I have no idea what could be causing this error; (



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38bhfG3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire