We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I get the current Vertical Offset of a WPF PdfViewer control

I tried getting a reference to the scrollviewer but the VerticalOffset is always 0

7 Replies

AS Aravindh Sathiyamoorthy Syncfusion Team September 18, 2019 05:17 PM UTC

Hi Samuel, 

We can get the VerticalOffset from ScrollChanged event in PdfViewerControl. We have created a simple sample for the same and that can be downloaded from the below, 


Regards, 
Aravindh Sathiyamoorthy. 



SA Samuel September 19, 2019 10:49 PM UTC

The number I get in the VerticalOffset of the event arguments do not match the number I put in to .ScrollTo
I also need to have access without handling the event.


AS Aravindh Sathiyamoorthy Syncfusion Team September 20, 2019 01:46 PM UTC

Hi Samuel, 
 
Please find the details below, 
 
Query 
Details 
The number I get in the VerticalOffset of the event arguments do not match the number I put in to .ScrollTo 
We have modified the sample to achieve your requirement and that can be downloaded from the below link, 
 
 
Kindly use the above sample and let us know that meets your requirement or not. 
I also need to have access without handling the event. 
At present, we do not have support to get the VerticalOffset from PdfViewerControl directly. However, we will validate your requirement and provide you further details on 17th September 2019.  
 
 
Regards,
Aravindh Sathiyamoorthy.
 



SA Samuel September 20, 2019 02:22 PM UTC

Try this example with adding the following line before the call to ScrollTo

pdfViewerControl.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.FitWidth;



Just to be clear what I'm trying to accomplish.
I'm trying to programmatically scroll one screen at a time (page down).


AS Aravindh Sathiyamoorthy Syncfusion Team September 23, 2019 12:49 PM UTC

Hi Samuel, 
 
Please find the details below, 
 
Query 
Details 
Try this example with adding the following line before the call to ScrollTo 
 
pdfViewerControl.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.FitWidth; 
 
We can able to reproduce the issue “VerticalOffset is not same in ScrollChanged event if we applied ZoomMode in PdfViewerControl”. That was fixed in the sample itself. Please find the below link to get the modified sample, 
 
 
Please use the above sample and let us know whether it meets your requirement or not. If not, kindly share the following details to analyze more on this issue and assist you with the better solution  
1.       Simple sample/ modify the above sample with the issue PDF document to reproduce the issue. 
2.       Replication procedure to reproduce the issue. 
3.       Product version of PdfViewerControl that you have been using. 
 
I also need to have access without handling the event.  
We will implement the requirement of “Support to get the Vartical Offset from PdfViewerControl” by considering it as a usability feature. The patch for the same will be available on 7th October 2019.  
 
 
 
Regards, 
 
Aravindh Sathiyamoorthy. 




PG Pon Geetha A J Syncfusion Team September 24, 2019 04:49 AM UTC

This is still not accurate 
 
 
This also relies on all pages being the same size. This isn’t always the case in PDF documents. 
 
I’m using the latest version of the controls. 
 
Here is the solution that seems to work for me: (PART_ScrollViewer seems to be the name of the scrollviewer that controls the actual page) 
Since you would have direct access to that scrollviewer, you really would only need the first method. 
 
        private static void ScrollPage(this PdfViewerControl pdf, bool pageDown) 
        { 
            var sv = pdf.FindVisualChild<ScrollViewer>("PART_ScrollViewer"); 
            sv.ScrollToVerticalOffset(sv.ContentVerticalOffset + (pageDown ? sv.ViewportHeight * .95 : -sv.ViewportHeight *.95)); 
        } 
 
        public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject depObj) where T : DependencyObject 
        { 
            if (depObj != null) 
            { 
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) 
                { 
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i); 
                    if (child != null && child is T) 
                    { 
                        yield return (T)child; 
                    } 
 
                    foreach (T childOfChild in FindVisualChildren<T>(child)) 
                    { 
                        yield return childOfChild; 
                    } 
                } 
            } 
        } 
        public static childItem FindVisualChild<childItem>(this DependencyObject obj, string name) where childItem : FrameworkElement 
        { 
            foreach (childItem child in FindVisualChildren<childItem>(obj)) 
            { 
                if (child.Name == name) return child; 
            } 
 
            return null; 
        } 



AS Aravindh Sathiyamoorthy Syncfusion Team September 25, 2019 12:25 PM UTC

Hi Samuel,  
 
We are glad to know that the issue is resolved. Kindly get back to us if you need any further assistance. 
 
Regards, 
Aravindh Sathiyamoorthy. 


Loader.
Live Chat Icon For mobile
Up arrow icon