title: Subtotal at the end of each A4 pdf in laravel 8
body: <p>I use laravel 8 and would like to create an offer as a pdf with a subtotal at the end of A4.</p>
  <p>that means if I have several A4 files I should always show a subtotal at the end</p>
  <pre><code>@if(count($more_data) &gt; 0)
      &lt;?php 
      $temp_data = array();
      foreach($more_data as $rs){
          $temp_data = json_decode($rs-&gt;temp_data);
      } 
  
      $temp_data = json_decode(json_encode($temp_data), true);
      
      $cnt = 1; 
      $final_total = 0;
      $vat = get_vat_price();
      if(count($temp_data) &gt; 0){
          foreach($temp_data as $key=&gt;$tmp_data){ ?&gt;
              &lt;table class=&quot;offr_tbl w-100 mb-5&quot;&gt; 
                  &lt;thead&gt;
                      &lt;tr class=&quot;text-left&quot;&gt;
                          &lt;th&gt;Pos.&lt;/th&gt;       
                          &lt;th&gt;Anzahl&lt;/th&gt;
                          &lt;th&gt;Einheit&lt;/th&gt;
                          &lt;th&gt;Bezeichnung&lt;/th&gt;
                          
                          @if($usr_type == &quot;admin&quot;)
                              &lt;th&gt;Einzelpreis&lt;/th&gt;
                              &lt;th&gt;Gesamtpreis&lt;/th&gt;
                          @endif
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
              &lt;?php foreach($tmp_data as $key1=&gt;$tmp_data1){ ?&gt;
                  &lt;tr&gt;
                      &lt;td class=&quot;text-left top_rows&quot; colspan=&quot;6&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;strong&gt;{{ $key1 }}&lt;/strong&gt;&lt;/td&gt;
                  &lt;/tr&gt;   
                  &lt;?php foreach($tmp_data1 as $key2=&gt;$tmp_data2){ ?&gt;
                      &lt;tr class=&quot;bordr&quot;&gt;
                          &lt;td class=&quot;text-left top_rows&quot; colspan=&quot;6&quot;&gt;&lt;strong&gt;{{ $key2 }}&lt;/strong&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;?php foreach($tmp_data2 as $key3=&gt;$fields){
                              $sub_total = 0;
                          if(is_array($fields['field_id'])){
                              $abc = array_merge_recursive($fields['field_id'], $fields['quantity']);
                              
                              $cnt1 = 0;
                              foreach($fields['field_id'] as $field){
                                  $field_name = get_field_data($field, 'field_name');
                                  $quantity   = $fields['quantity'][$cnt1];
                                  
                                  $description  = get_field_data($field, 'description');
                                  $measure_type = get_field_measure_type($field);
                                  
                                  if($usr_type == &quot;admin&quot;){
                                      $cost       = $fields['cost'][$cnt1]; 
                                      $total = ($quantity * $cost);
                                      $sub_total = $total + $sub_total; 
                                      $final_total = $total + $final_total;
                                  }
                              ?&gt; 
                                  &lt;tr class='item_data'&gt;
                                      &lt;td class=&quot;text-left&quot;&gt;{{ $cnt }})&lt;/td&gt;
                                      &lt;td class=&quot;text-center&quot;&gt;{{ $quantity }}&lt;/td&gt;
                                      &lt;td class=&quot;text-center&quot;&gt;{{ $measure_type }}&lt;/td&gt;
                                      &lt;td class=&quot;text-left&quot;&gt;
                                          &lt;b&gt;{{ $field_name }}&lt;/b&gt; &lt;br&gt;
                                          {!! $description !!}
                                      &lt;/td&gt;
                                      
                                      @if($usr_type == &quot;admin&quot;)
                                          &lt;td class=&quot;text-center&quot;&gt;{{ $cost }} €&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ $total }} €&lt;/td&gt;
                                      @endif
                                  &lt;/tr&gt;   
                                   
                                  &lt;?php  
                                  $extra_fields = getExtraFields($field); 
                                  $cnt++;
                                  $cnn = $cnt;
                                  foreach($extra_fields as $extra_field){ 
                                      $total       = ($quantity * $extra_field-&gt;cost_per_quantity);
                                      $sub_total   = $total + $sub_total;
                                      $final_total = $total + $final_total;
                                  ?&gt; 
                                      &lt;tr class='item_data'&gt;
                                          &lt;td class=&quot;text-left&quot;&gt;{{ $cnn }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ $quantity }} Pc.&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ $extra_field-&gt;measure_type }}&lt;/td&gt;
                                          &lt;td class=&quot;text-left&quot;&gt;
                                              &lt;b&gt;{{ $extra_field-&gt;field_name }}&lt;/b&gt; &lt;br&gt;
                                              {!! $extra_field-&gt;description !!}
                                          &lt;/td&gt;
                                          @if($usr_type == &quot;admin&quot;)
                                              &lt;td class=&quot;text-center&quot;&gt;{{ $extra_field-&gt;cost_per_quantity }} €&lt;/td&gt;
                                              &lt;td class=&quot;text-center&quot;&gt;{{ $total }} €&lt;/td&gt;
                                          @endif
                                      &lt;/tr&gt; 
                                  &lt;?php $cnn++;
                                  }
                                                                                          
                                  $cnt = $cnn;
                                  
                                  $cnt1++;
                              }
                          }else{
                              $field_name = get_field_data($fields['field_id'], 'field_name');
                              $quantity = $fields['quantity'];
                              
                              $description = get_field_data($fields['field_id'], 'description');
                              $measure_type = get_field_measure_type($fields['field_id']);
                              
                              if($usr_type == &quot;admin&quot;){
                                  $cost     = $fields['cost'];
                                  $total = ($quantity * $cost);
                                  $sub_total = $total + $sub_total;
                                  $final_total = $total + $final_total;
                              }
                              ?&gt; 
                              &lt;tr class=&quot;bordr item_data&quot;&gt;
                                  &lt;td class=&quot;text-left&quot;&gt;{{ $cnt }}&lt;/td&gt;
                                  &lt;td class=&quot;text-center&quot;&gt;{{ $quantity }} Pc.&lt;/td&gt;
                                  &lt;td class=&quot;text-center&quot;&gt;{{ $measure_type }}&lt;/td&gt;
                                  &lt;td class=&quot;text-left&quot;&gt;
                                      &lt;b&gt;{{ $field_name }}&lt;/b&gt; &lt;br&gt;
                                      {!! $description !!}
                                  &lt;/td&gt;
                                  @if($usr_type == &quot;admin&quot;)
                                      &lt;td class=&quot;text-center&quot;&gt;{{ $cost }} €&lt;/td&gt;
                                      &lt;td class=&quot;text-center&quot;&gt;{{ $total }} €&lt;/td&gt;
                                  @endif
                              &lt;/tr&gt;
                              
                              &lt;?php  
                              $extra_fields = getExtraFields($fields['field_id']); 
                              $cnt++;
                              $cnn = $cnt;
                              foreach($extra_fields as $extra_field){ 
                                  $total       = ($quantity * $extra_field-&gt;cost_per_quantity);
                                  $sub_total   = $total + $sub_total;
                                  $final_total = $total + $final_total;
                              ?&gt; 
                                  &lt;tr class=&quot;bordr item_data&quot;&gt;
                                      &lt;td class=&quot;text-left&quot;&gt;{{ $cnn }}&lt;/td&gt;
                                      &lt;td class=&quot;text-center&quot;&gt;{{ $quantity }} Pc.&lt;/td&gt;
                                      &lt;td class=&quot;text-center&quot;&gt;{{ $extra_field-&gt;measure_type }}&lt;/td&gt;
                                      &lt;td class=&quot;text-left&quot;&gt;
                                          &lt;b&gt;{{ $extra_field-&gt;field_name }}&lt;/b&gt; &lt;br&gt;
                                          {!! $extra_field-&gt;description !!}
                                      &lt;/td&gt;
                                      @if($usr_type == &quot;admin&quot;)
                                          &lt;td class=&quot;text-center&quot;&gt;{{ $extra_field-&gt;cost_per_quantity }} €&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ $total }} €&lt;/td&gt;
                                      @endif
                                  &lt;/tr&gt; 
                              &lt;?php $cnn++;
                              }
                                                                                      
                              $cnt = $cnn;
                          } ?&gt;
                          
                          @if($usr_type == &quot;admin&quot;)
                              &lt;tr class=&quot;bordr sb_t&quot;&gt;
                              &lt;td colspan=&quot;2&quot; class=&quot;text-left&quot;&gt;
                                  Zwischensumme
                              &lt;/td&gt;
                              &lt;td colspan=&quot;3&quot;&gt;&lt;/td&gt;
                              &lt;td class=&quot;text-center&quot;&gt;{{ $sub_total }} €&lt;/td&gt;
                              &lt;/tr&gt;
                          @endif
                  &lt;?php }
                  }
              } ?&gt;
              
              &lt;?php
              $add_cost = (getDefaultValue('additional_cost_per_qty_1') ) * (getDefaultValue('additional_cost_qty_1'));
              $final_total = $add_cost + $final_total;
              ?&gt;
              &lt;tr class='item_data'&gt;
                  &lt;td class=&quot;text-left&quot;&gt;{{ $cnn }}&lt;/td&gt;
                  &lt;td class=&quot;text-center&quot;&gt;{{ getDefaultValue('additional_cost_qty_1') }}&lt;/td&gt;
                  &lt;td class=&quot;text-center&quot;&gt;{{ getDefaultValue('additional_cost_measure_type_1') }}&lt;/td&gt;
                  &lt;td class=&quot;text-left&quot;&gt;
                      &lt;b&gt;{{ getDefaultValue('additional_cost_title_1') }}&lt;/b&gt; &lt;br&gt;
                      {!! getDefaultValue('additional_cost_description_1') !!}
                  &lt;/td class=&quot;text-center&quot;&gt;
                  @if($usr_type == &quot;admin&quot;)
                      &lt;td class=&quot;text-center&quot;&gt;{{ getDefaultValue('additional_cost_per_qty_1') }} €&lt;/td&gt;
                      &lt;td class=&quot;text-center&quot;&gt;{{ $add_cost }} €&lt;/td&gt;
                  @endif
              &lt;/tr&gt; 
                  
              &lt;?php
              $add_cost = (getDefaultValue('additional_cost_per_qty_2') ) * (getDefaultValue('additional_cost_qty_2'));
              $final_total = $add_cost + $final_total;
              
              $cnn++;
              ?&gt;
              &lt;tr class='item_data'&gt;
                  &lt;td class=&quot;text-left&quot;&gt;{{ $cnn }}&lt;/td&gt;
                  &lt;td class=&quot;text-center&quot;&gt;{{ getDefaultValue('additional_cost_qty_2') }} Pc.&lt;/td&gt;
                  &lt;td class=&quot;text-center&quot;&gt;{{ getDefaultValue('additional_cost_measure_type_2') }}&lt;/td&gt;
                  &lt;td class=&quot;text-left&quot;&gt;
                      &lt;b&gt;{{ getDefaultValue('additional_cost_title_2') }}&lt;/b&gt; &lt;br&gt;
                      {!! getDefaultValue('additional_cost_description_2') !!}
                  &lt;/td&gt;
                  @if($usr_type == &quot;admin&quot;)
                      &lt;td class=&quot;text-center&quot;&gt;{{ getDefaultValue('additional_cost_per_qty_2') }} €&lt;/td&gt;
                      &lt;td class=&quot;text-center&quot;&gt;{{ $add_cost }} €&lt;/td&gt;
                  @endif
              &lt;/tr&gt; 
                  
              @if($usr_type == &quot;admin&quot;)
                  &lt;tr class=&quot;sb_totl&quot;&gt;
                      &lt;td colspan=&quot;2&quot; class=&quot;text-left&quot;&gt;
                          &lt;strong&gt;Summe&lt;/strong&gt;
                      &lt;/td&gt;
                      &lt;td colspan=&quot;3&quot;&gt;&lt;/td&gt;
                      &lt;td class=&quot;text-center&quot;&gt;&lt;strong&gt;{{ $final_total }} €&lt;/strong&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td colspan=&quot;5&quot; class=&quot;text-left&quot;&gt;
                          &lt;strong&gt;Mehrwertsteuer {{ $vat }}% auf {{ $final_total }} € netto&lt;/strong&gt;
                      &lt;/td&gt;
                      &lt;td class=&quot;text-center&quot;&gt;&lt;strong&gt; 
                      &lt;?php
                       $tax = ($final_total * $vat)/100;
                      ?&gt;
                      {{ $tax }} €&lt;/strong&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  
                  &lt;tr class=&quot;last_row&quot;&gt;
                      &lt;td colspan=&quot;5&quot; class=&quot;text-left&quot;&gt;
                          Zu zahlender betrag
                      &lt;/td&gt;
                      &lt;td class=&quot;text-center&quot;&gt;
                          &lt;?php
                           $final_total = $final_total + $tax;
                           echo $final_total. &quot; €&quot;;
                          ?&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              @endif
              
              &lt;/tbody&gt;        
          &lt;/table&gt;
          &lt;?php }
      }
      ?&gt;
  @endif
  </code></pre>
  <p>I searched google but couldn't find a suitable answer.</p>
  <p>is it possible to know when is the end of A4 with laravel?</p>
  <p>I hope that one of you can help me.</p>