Page number with DOMPDF and LARAVEL

0

How do I put the number of each page with domPDF? I use it with laravel.

Example: Page 1-4, Page 2-4, Page 3-4, and Page 4-4;

My function for fetching bank data:

public function print($id) {
        $budget = Budget::find($id);
        $budgetItems = BudgetItem::where('budget_id', '=', $budget->id)->get();
        $pdf = PDF::loadView('reports.budgetprint', ['budget' => $budget, 'budgetItems' => $budgetItems]);
        return $pdf->stream('budgetprint.pdf');
    }

And my rendering:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Report Quote</title>
</head>
<body>

    <div class="text-center">
      <img src="<?php echo public_path() . '/images/logoreport.png'; ?>" alt="Logo" width="300px">
    </div>

    <p>
      <span><strong>Client:</strong> {{ $budget->client_name }};</span>
      <span style="float: right;"><strong>Date:</strong> {{ date_format(new DateTime($budget->created_at), 'm-d-Y') }}</span>
    </p>

    <p>{{ $budget->client_address }}</p>
    <p>
      <span><strong>Cell:</strong> {{ $budget->client_phone }} / {{ $budget->client_cell_phone }}</span>
      <span style="float: right;"><strong>E-mail:</strong> {{ $budget->client_email }}</span>
    </p>

    <hr>

    <table class="table table-bordered table-condensed" style="margin-bottom: 100px;">
        <thead>
            <tr>
                <th style="width: 50px;">Room</th>
                <th>Items</th>
                <th style="width: 40px; text-align: center;">Qty</th>
                <th style="width: 80px; text-align: center;">Price</th>
                <th style="width: 80px; text-align: center;">Subtotal</th>
            </tr>
        </thead>
        <tbody>
          <tr>
              <td style="text-align: center;">-</td>
              <td>{{ $budgetItem->name }}</td>
              <td style="text-align: center;">{{ $budgetItem->amount }}</td>
              <td style="text-align: center;">{{ number_format($budgetItem->price, 2, '.', ',') }}</td>
              <td style="text-align: center;">{{ number_format($budgetItem->subtotal, 2, '.', ',') }}</td>
          </tr>
        </tbody>
    </table>
</body>
</html>

Thanks for the help.

    
asked by anonymous 17.10.2018 / 01:19

1 answer

0

A basic example:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel</title>           
    </head>
    <body>      
        @foreach($items as $item)
            <div>{{$item}}</div>
        @endforeach
        <script type='text/php'>
            if (isset($pdf)) 
            {               
                $pdf->page_text(60, $pdf->get_height() - 50, "{PAGE_NUM} de {PAGE_COUNT}", null, 12, array(0,0,0));
            }
        </script>
    </body>
</html>

that is, $ items is value that I send and I loop the information repetition and where it has <script type='text/php'> the pagination is processed.

No controller add $pdf->getDOMPdf()->set_option('isPhpEnabled', true); to work previous code, example:

<?php namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ViewPdfController extends Controller
{
    public function index()
    {
        for ($i=0; $i < 100; $i++) 
        { 
            $items[$i] = $i + 1;
        }
        $pdf = \App::make('dompdf.wrapper');
        $pdf->loadView('dompdf', ['items' => $items]);  
        $pdf->getDOMPdf()->set_option('isPhpEnabled', true);            
        return $pdf->stream();
    }
}
    
18.10.2018 / 03:47