0

As per documentation, we print the page number on each pdf page but my problem is I want to use the PHP variables inside dom script tag which I can't do that.

<script type="text/php">
    if (isset($pdf)) {
      $font = $fontMetrics->getFont("Arial", "bold");
      $pdf->page_text(555, 745, "{PAGE_NUM}", $font, 7, array(0, 0, 0));
    }
</script>

@php
   $page = "{PAGE_NUM}";// it prints the string "{PAGE_NUM}" but I want current page number here
@endphp

My problem is that I want to use this {PAGE_NUM} inside my normal @php laravel blade file tag so that I can be able to detect the page change. Is there any way to do this stuff?.

Zain Farooq
  • 2,956
  • 3
  • 20
  • 42
  • This placeholder syntax will only get evaluated when you are using methods like `page_text`, you can not expect them to work outside of that context. I don’t think what you want here is actually possible. You are probably feeding the (complete?) output of your template _to_ the PDF writer at some point, yet you also want information _from_ the PDF writer, _while_ that template output is created? Can’t see that happening, with time moving only in one direction and all … – CBroe Mar 31 '21 at 07:34
  • I guess your only option is to feed smaller chunks of content to the writer bit by bit, so that you can get information back from it in between. – CBroe Mar 31 '21 at 07:35
  • @CBroe I want to calculate the sum of the amount which is in the table rows `tr` at the end of the page or at the beginning of the very next page. That's why I need to detect the page change. – Zain Farooq Mar 31 '21 at 09:15
  • I know that `{PAGE_NUM}` is just a param in `page_text`. – Zain Farooq Mar 31 '21 at 09:20
  • _“That's why I need to detect the page change.”_ - but this is a chicken-and-egg problem. You pass output from your template to the PDF writer, and only _while_ it is converting that output to PDF, the writer is able to determine when it needs to start a new page. How do you expect to pass information back to the template now – it _has_ already rendered at this point, so unless you have a time machine, how should this be possible? Therefor, you will need a different approach - add output to the PDF row-by-row, and finding a way to determine when a page break would occur. – CBroe Mar 31 '21 at 09:31
  • Hmm.. "_finding a way to determine when a page break would occur._" I am actually finding the way – Zain Farooq Mar 31 '21 at 09:51

0 Answers0