How to get the scroll position...

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

dlyohan
User
Posts: 1
Joined: Thu May 26, 2011 11:35 pm

How to get the scroll position...

Post by dlyohan »

Now I am trying to make a application using WPF/c#.
In this application, I looked at prototyping this XChange viewer SDK
but do not know if I can get a scroll event notification from the control,
or if I can find the current scroll position of each page on the screen.

I am looking for an event such as ScrollPositionChanged (or document position changed) that would allow me to then interrogate the current HScollPos and VScrollPos on the instance raising the event and set these same values on the other layer control of WPF.

Is there any way to get this information from XChange Viewer SDK ?

regards,
yohan.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: How to get the scroll position...

Post by Vasyl - PDF-XChange »

Hi, Yohan.

Sorry, no way for this in current version. Please wait for version V3.

Best
regards.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
vzgherea
User
Posts: 23
Joined: Mon Sep 09, 2013 8:38 am

Re: How to get the scroll position...

Post by vzgherea »

Looking for the same event as topic starter - scroll event notification.
Is it available in the current version of SDK?
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: How to get the scroll position...

Post by Vasyl - PDF-XChange »

Hi, vzgherea and yohan.

Now exists one new undocumented feature to synchronize scroll positions of two(or more) opened documents.

Methods:
Document::GetVPos()
Document::SetVPos()
Event:
Type=PXCVA_OnNamedNotify, Name="Notifications.ScrollChanged"

Look to attached C# example that displays it.

Also you may use next trick. To get current view position:

Code: Select all

struct ScrollPos
{
   int         pageIndex;
   double    x;  
   double    y;
}

ScroolPos spos;

object dataIn;
object dataOut;
GetDocumentProperty(docID, "Pages.Current", out dataOut, PXVA_Sync);

spos.pageIndex = dataOut;

// [0,0] screen point to pdf-coord. system of current page:
DoDocumentVerb(docID, "Pages[" + spos.pageIndex + "]", "TranslateScreenPoint", dataIn(0, 0), out dataOut, PXVA_Sync);
spos.x = dataOut[0];
spos.y = dataOut[1];
To restore the previously saved view position:

Code: Select all

DoDocumentVerb(docID, "Pages[" + spos.pageIndex + "]", "MovePointToScreenPoint", dataIn(spos.x, spos.y, 0, 0), null, PXVA_Sync);
HTH
You do not have the required permissions to view the files attached to this post.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
vzgherea
User
Posts: 23
Joined: Mon Sep 09, 2013 8:38 am

Re: How to get the scroll position...

Post by vzgherea »

Many thanks for your post, it is very helpful!

But I can't still solve my issue. I am implementing document compare functionality. Each document has only one page and is loaded in it's own control. It is necessary to synchronize scrolling in both controls and it has to be done proportionally, e.g. 50% of scrolling in first control has to set scrolling to 50% in the second control, even in case size of pages is different or orientation of pages is different.

Could you give me a hint how this could be achieved?
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: How to get the scroll position...

Post by Vasyl - PDF-XChange »

It is necessary to synchronize scrolling in both controls and it has to be done proportionally, e.g. 50% of scrolling in first control has to set scrolling to 50% in the second control, even in case size of pages is different or orientation of pages is different.
You may try to use one undocumented way:

Code: Select all

m_bSkipScrollEvent = false;
axCoPDFXCview1.SetProperty("Notifications.ScrollChanged.Enabled", 1, 0);
axCoPDFXCview2.SetProperty("Notifications.ScrollChanged.Enabled", 1, 0);
...
youreventhandker axCoPDFXCview1_OnEvent(type, name, dataIn)
{
     if (!m_bSkipScrollEvent && (type == PXCV_OnNamedNotify) AND (name == "Notifications.ScrollChanged"))
     {
           m_bSkipScrollEvent = true;
           LONG pageIndex  = dataIn[0];
           double dxPage = dataIn[3];
           double dyPage = dataIn[4];
           double pw, ph; 
           axCoPDFXCview1.GetDocumentProperty(0, "Pages[ + pageIndex + "].Width", out pw, PXCVA_NoUI | PXCVA_Sync);
           axCoPDFXCview1.GetDocumentProperty(0, "Pages[ + pageIndex + "].Height", out ph, PXCVA_NoUI | PXCVA_Sync);
           double xz = dxPage / pw;
           double yz = dyPage / ph;

           double pw, ph; 
           axCoPDFXCview2.GetDocumentProperty(0, "Pages[ + pageIndex + "].Width", out pw, PXCVA_NoUI | PXCVA_Sync);
           axCoPDFXCview2.GetDocumentProperty(0, "Pages[ + pageIndex + "].Height", out ph, PXCVA_NoUI | PXCVA_Sync);
           dxPage = pw * xz;
           dyPage = ph * yz;

           dataIn[3] = dxPage;
           dataIn[4] = dyPage;

           axCoPDFXCview2.DoDocumentVerb(0, "", "SetVPos", dataIn, null, PXCVA_NoUI | PXCVA_Sync);

           m_bSkipScrollEvent = false;
     }
}
...
youreventhandker axCoPDFXCview2_OnEvent(type, name, dataIn)
{
     if (!m_bSkipScrollEvent && (type == PXCV_OnNamedNotify) AND (name == "Notifications.ScrollChanged"))
     {
           m_bSkipScrollEvent = true;
           LONG pageIndex  = dataIn[0];
           double dxPage = dataIn[3];
           double dyPage = dataIn[4];
           double pw, ph; 
           axCoPDFXCview2.GetDocumentProperty(0, "Pages[ + pageIndex + "].Width", out pw, PXCVA_NoUI | PXCVA_Sync);
           axCoPDFXCview2.GetDocumentProperty(0, "Pages[ + pageIndex + "].Height", out ph, PXCVA_NoUI | PXCVA_Sync);
           double xz = dxPage / pw;
           double yz = dyPage / ph;

           double pw, ph; 
           axCoPDFXCview1.GetDocumentProperty(0, "Pages[ + pageIndex + "].Width", out pw, PXCVA_NoUI | PXCVA_Sync);
           axCoPDFXCview1.GetDocumentProperty(0, "Pages[ + pageIndex + "].Height", out ph, PXCVA_NoUI | PXCVA_Sync);
           dxPage = pw * xz;
           dyPage = ph * yz;

           dataIn[3] = dxPage;
           dataIn[4] = dyPage;

           axCoPDFXCview1.DoDocumentVerb(0, "", "SetVPos", dataIn, null, PXCVA_NoUI | PXCVA_Sync);

           m_bSkipScrollEvent = false;
     }
}
This method will work only for Pages.Layout == SinglePage or Pages.Layout == One Column Continuous

HTH
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.