find the total page number of pdf report

Hello,
I’m working on a pdf report (invoice) application, and i whould like to kow the total
number of page of my report, because I want to write a footer only in the last page of the
invoice.
After lots of search, I found the sc_pdf_page_tot() function, but I can’t return it’s
value in a variable.

I create a new cell “cell_footer_total” and put it in the body of my pdf report.
In Layout PDF interface body I choose the option “Total Page”.
And After When I go to layout PDF > code >body I can see

sc_pdf_page_tot($cell_footer_total);

I want to know “when I come on the last page”, my project is to check :

if(sc_pdf_page_no == sc_pdf_page_tot){ //that means I'm in the last page
// so write the footer
}

precise the page where I can find the function which return the total page of the report.
In this manual you speak about Field
Description

{sc_page_num} Current page number.
{sc_page_tot} Total number of pages.

BUT these 2 variables do not work

Somebody help?

Re: find the total page number of pdf report

Don’t know if this helps but if you put

sc_pdf_text(x,y,’{nb}’);

then it prints the total number of pages in the the coordinate x,y.

so, maybe you could check your if statement with ‘{nb}’…

Re: find the total page number of pdf report

{nb} is field right??

Re: find the total page number of pdf report

{sc_page_num} Current page number.
{sc_page_tot} Total number of pages.

I had the same problem two years ago. Nice to hear that these two variables are not working yet. (sadly spoken)
I helped myself with counting the records dividing by max number of records per page. With that workaround
I was able to know where my script is and which info I need to bring into the report …

For future projects I would love these variables would work

Best regards

Eric

Re: find the total page number of pdf report

There was an example in fpdf.org and i got the idea from there. {nb} is not a SC field. They were using {nb} to just get the total number of page in that example, which i tried putting in the code part of PDF app in SC and was working.

Example from fpdf.org under manual --> AliasNbPages:

class PDF extends FPDF
{
function Footer()
{
//Go to 1.5 cm from bottom
$this->SetY(-15);
//Select Arial italic 8
$this->SetFont(‘Arial’,‘I’,8);
//Print current and total page numbers
$this->Cell(0,10,‘Page ‘.$this->PageNo().’/ {nb}’,0,0,‘C’);
}
}

$pdf=new PDF();
$pdf->AliasNbPages();