PDFViewCtrl.SetZoom and PDFViewCtrl.OnPageNumberChanged caused infinite loop

I’m trying to set my PDF to show on the WinRT device with zoom set to a certain percentage using the SetZoom() method. I can get it to work on the first page when the PDF first gets loaded, but when I swipe left to go to the next page, my zoom gets cleared and the second page shows the entire page instead of retaining my zoom.

I tried to fix this by tapping into the OnPageNumberChanged event and use the SetZoom() method again on each page change. But when I do this, I noticed that the OnPageNumberChanged event will result in an infinite loop. Here is my OnPageNumberChanged method:

`
void mPDFView_OnPageNumberChanged(int __param0, int __param1)
{
mPDFView.SetPageViewMode(pdftron.PDF.PDFViewCtrlPageViewMode.e_zoom);
mPDFView.SetZoom(zoom);
}

`

The variable “zoom” is pre-calculated when the PDF gets loaded into the viewer and when I put a breakpoint at the beginning of this event handler, I will experience the infinite loop as soon as I swipe left on a PDF. The problem seems to be related to the SetZoom() method because if I comment that line out (so I ended up with only the SetPageViewMode() method), I do not get the infinite loop.

Please advise.

In OnPageNumberChanged() callback you can’t call any method that would change page # … since you end up in infinite loop.

Instead you need to post the message (Send/PostMessage in WIN32 world, not sure what would be the equivalent in WinRT) to your app and then process the command when after you return from page change callback

Thanks for the hint.

For those of you who are having this issue in the future, here’s what I ended up with in my OnPageNumberChanged():
Note that I added a boolean variable called resizeProcessed and defaulted it to false, and another integer variable called currentPage to keep track of the currently displayed page number.

`

void mPDFView_OnPageNumberChanged(int __param0, int __param1)
{
if (currentPage != mPDFView.GetCurrentPage() && !resizeProcessed)
{
resizeProcessed = true;
currentPage = mPDFView.GetCurrentPage();
mPDFView.SetPageViewMode(pdftron.PDF.PDFViewCtrlPageViewMode.e_zoom);
mPDFView.SetZoom(zoom);
}
else
{
resizeProcessed = false;
}
}

`