Do you really need the preview step? It isn't necessary in order to save as PDF and most reports these days can look much the same in browse mode as they do in preview with the except of a few details such as page numbers and such.
You can also use
IF [ Not patterncount ( Get(ApplicationVersion) "Go" ) ]
Enter Preview Mode
to skip the step when the file is open on an iOS device.
Your code will work on some reports.
However, I do require page numbering on the vast majority of the reports. Is there a different way to paginate?
Try the Report View. It produces very nice sorted reports that one can scroll through and thus eliminates the need for printing but you can via a button.
I am not sure what "Report View" is. Can you please explain. And will it allow me to paginate reports?
But do you need to see the page numbering before you save it as PDF? The PDF will contain the page numbers--they just don't show in browse mode on your screen.
It is required that the reports use the "XX of YY" page numbering format where XX is the current page and YY is the total pages in the report (see my post from July 2 above which has a screen capture illustrating this). I use the following code to calculate the number of pages gnerated by each layout in the report. The total number of pages is stored in a variable and then used in the second pass through the code to create the final report.
Code Used To Generate Report and Keep Track of Total Number of Pages
With some reports, it's possible to calculate the number of pages from the number of records--even if you have sub summary parts if you count the number of groups. That's a process that is more complicated, but can avoid having to enter preview mode.
It won't be possible if your report layout includes objects that slide up and resize.