PDF page of x pages AdvGridPDFIO

I need the "1 of 3" page display on the PDF that was created by
AdvStringGrid --> TAdvGridPDFIO.

So if my PDF consists of 3 pages, the first page should show 1 of 3, the second page 2 of 3 and the third page 3 of 3.

My approach was:

tRowHeight = Row height stringgrid

    tAzRowSite := AdvGridPDFIO.PageHeight - AdvGridPDFIO.Options.Margins.Top - AdvGridPDFIO.Options.Margins.Bottom) div tRowHeight;
    tmAnzPage := Trunc((AdvStringGrid.RowCount+1) / tAzRowSite) + 1;

When I measure the whole thing in the finished PDF, the Rowheight = 20 and the page height 1153.
and it has 57 lines

The page height shown with AdvGridPDFIO.PageHeight queried is 842
the margins are each 40
rowheight is 18
with my calculation this results in 42 (.33333) lines

Is there another solution that provides the correct result?
I could also create the PDF two times and remember the max page. But that's not so cool.

Unfortunately it's not possible to calculate the number of pages it needs. We'll investigate the possibilities

Ok