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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PDF Document Programmatic Zoom

Thread ID:

Created:

Updated:

Platform:

Replies:

141598 Dec 19,2018 09:55 PM UTC Mar 14,2019 06:22 AM UTC WinForms 7
loading
Tags: PdfViewer
Darrin Edwards
Asked On December 19, 2018 09:55 PM UTC

Hi guys

Using VS2017 on Windows 10 Professional with version 16.3460.0.21 of the PDF Controls. In the code below PDFViewerEx is the name of the form and ViewerCtl is a PdfViewer.PdfDocumentView.

I am trying to make the control zoom with the user using the mousewheel and control key and whilst it is working, I have found what I believe to be a bug. Code follows.

The bug I believe is only in the zoom up functionality - the control move up a page on each scroll and I cater for that by adjusting the page back - that of course is an issue. Can you confirm my code is correct and confirm that there is a bug?


.. 
        enum ZoomDirection { None, Up, Down };

        private void PDFViewerEx_KeyDown(object sender, KeyEventArgs e)
        {
            CtrlIsDown = e.Control;

        }
        private void PDFViewerEx_MouseWheel(object sender, MouseEventArgs e)
        {
            //check if control is being held down
            int page = ViewerCtl.CurrentPageIndex;
            Debug.WriteLine("In mousewhereel event - Zoom Up - page " + ViewerCtl.CurrentPageIndex.ToString());
            if (CtrlIsDown)
            {
                //evaluate the delta's sign and call the appropriate zoom command
                int i = Math.Sign(e.Delta);
                if (i < 0)
                {
                    Zoom(ZoomDirection.Down);

                }
                else if (i > 0)
                {
                    Zoom(ZoomDirection.Up);
                    Debug.WriteLine("In mousewhereel event - Zoom Up1 - page " + ViewerCtl.CurrentPageIndex.ToString());
                    if (page > 1)
                        ViewerCtl.GoToPageAtIndex(page + 1);
                    else
                        ViewerCtl.GoToPageAtIndex(page);

                    Debug.WriteLine("In mousewhereel event - Zoom Up2 - page " + ViewerCtl.CurrentPageIndex.ToString());
                }
            }
        }
        void Zoom(ZoomDirection zd)
        {
            int ZoomLevel = ViewerCtl.ZoomPercentage;
            //Debug.WriteLine("In Zoom event " + ZoomLevel.ToString());
            switch (zd)
            {
                case ZoomDirection.Up:
                    ViewerCtl.ZoomTo(ZoomLevel + 2);
                    break;
                case ZoomDirection.Down:
                    ViewerCtl.ZoomTo(ZoomLevel - 2);
                    break;
                case ZoomDirection.None:
                    ViewerCtl.ZoomTo(ZoomLevel);
                    break;

            }
            //Debug.WriteLine("After Zoom event " + ViewerCtl.ZoomPercentage.ToString());
            CtrlIsDown = false;
        }

        private void ViewerCtl_KeyDown(object sender, KeyEventArgs e)
        {
            CtrlIsDown = e.Control;
        }

        private void ViewerCtl_ZoomChanged(object sender, int zoomFactor)
        {
            Debug.WriteLine("In ViewerCtl_ZoomChanged event");
        }


Karthik Krishnaraj [Syncfusion]
Replied On December 24, 2018 12:19 PM UTC

Hi Darrin, 
 
Greetings from Syncfusion, 
 
On analyzing the provided code snippet, we came to know that you are performing zooming operation on Mouse wheel (Ctrl + mouse scroll) and trying to maintain the current page on zooming. But the page index moves up as reported by you. 
 
While performing zooming internally we have updated the page index based on verticalscrolloffset  
​So we suggest you to update the verticalscrolloffset instead of using GoToPageIndes() 
 
We have modified the provided sample to achieve your requirement of maintaining the page index and position, by using the VerticalScrollOffset and HorizontalScrollOffset of the control instead of CurrentPageIndex and GoToPageAtIndex methods. Please find the code snippet below. 
 
Before perform zooming (Take the backup of VerticalScrollOffset and HorizontalScrollOffset with respect to zoom percentage of 100) 
 
 
int backupVerticalOffset = ViewerCtl.VerticalScrollOffset / ViewerCtl.ZoomPercentage;
int backupHorizontalOffset = ViewerCtl.HorizontalScrollOffset / ViewerCtl.ZoomPercentage;
 
 
 
After perform zooming (Apply the backed up VerticalScrollOffset and HorizontalScrollOffset with respect to the current zoom percentage) 
 
 
ViewerCtl.VerticalScrollOffset = backupVerticalOffset * ViewerCtl.ZoomPercentage; 
ViewerCtl.HorizontalScrollOffset = backupHorizontalOffset * ViewerCtl.ZoomPercentage; 
 
 
 
Regards, 
Karthik. 


Darrin Edwards
Replied On December 26, 2018 04:20 AM UTC

Thanks Karthik, when did VerticalScrollOffset come into play ? It seems that the functionality is not available in 16.3*

MTIA

DWE

Darrin Edwards
Replied On December 26, 2018 07:17 AM UTC

Hello -the zoom function is still not working properly - it still scrolls up or down a fraction even in the example provided - I have uploaded a project which we can both work with if thats ok - its a bit easier using this example rather than the example you provided ...

Attachment: Zoom_Issue_20181226170514_ddbd49df.rar

Karthikeyan Chandrasekar [Syncfusion]
Replied On December 31, 2018 12:45 PM UTC

Hi Darrin, 
We are currently working in this feature and it will be available from our upcoming 2019 Vol-1 main release, which is expected to be available in the mid of March. 
Regards, 
Karthikeyan  


Darrin Edwards
Replied On January 7, 2019 11:52 PM UTC

Hi Karthik - I've resolved the scroll issue by the user of ScrollDisplacementValue as follows:

        void Zoom(ZoomDirection zd)
        {
            int backupVerticalOffset = ViewerCtl.VerticalScrollOffset / ViewerCtl.ZoomPercentage;
            int backupHorizontalOffset = ViewerCtl.HorizontalScrollOffset / ViewerCtl.ZoomPercentage;

            int page = ViewerCtl.CurrentPageIndex;
            int ZoomLevel = ViewerCtl.ZoomPercentage;
            //Debug.WriteLine("In Zoom event " + ZoomLevel.ToString());
            switch (zd)
            {
                case ZoomDirection.Up:
                    ViewerCtl.ZoomTo(ZoomLevel + 2);
                    //                    ViewerCtl.VerticalScrollOffset = (backupVerticalOffset) * ZoomLevel +2;// ViewerCtl.ZoomPercentage;
                    ViewerCtl.ScrollDisplacementValue = -10;
                    Debug.WriteLine("In Zoom event Zoom Direction.Up " + ZoomLevel.ToString());
                    break;
                case ZoomDirection.Down:
                    ViewerCtl.ZoomTo(ZoomLevel - 2);
                    ViewerCtl.ScrollDisplacementValue = 0;
                    Debug.WriteLine("In Zoom event Zoom Direction.Down " + ZoomLevel.ToString());
                    break;
                case ZoomDirection.None:
                    ViewerCtl.ZoomTo(ZoomLevel);
                    Debug.WriteLine("In Zoom event ZoomDirection.None " + ZoomLevel.ToString());
                    break;

            }
            ViewerCtl.VerticalScrollOffset = backupVerticalOffset * ViewerCtl.ZoomPercentage ;
            ViewerCtl.HorizontalScrollOffset = backupHorizontalOffset * ViewerCtl.ZoomPercentage;

            //Debug.WriteLine("After Zoom event " + ViewerCtl.ZoomPercentage.ToString());
            ctrlPressed = false;
        }

Sample code attached. Whilst it works for the moment, I'd be grateful if you would confirm once the bug has been ironed out in the next release.

Regards

Darrin

Attachment: Zoom_Issue__2_20190108094554_e8ff4ee2.rar

Ayswarya Krishna Kumar [Syncfusion]
Replied On January 8, 2019 09:14 AM UTC

Hi Darrin,  
  
Thank you for your update. 
  
As mentioned earlier currently we are working on this feature, we will ensure all the zoom operations on mouse functionality. We will update you with the details once the Volume 1 release is rolled out. 
  
Regards,  
Ayswarya 


Sathish Sivakumar [Syncfusion]
Replied On March 14, 2019 06:22 AM UTC

Hi All, 
 
We are glad to inform you that the feature Magnify PDF documents using CTRL key and mouse wheel where the mouse cursor is pointed to. has been included in our Essential Studio 2019 Volume 1 beta release  v17.1.0.32 and is available for download under the following link.  
 
 
Sample link: 
 
 
Regards, 
Sathish 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;