logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
Guest Posted: Wednesday, November 15, 2017 1:53:23 AM(UTC)
 
Thank you very much Paul, it works perfectly !
Paul Rayman Posted: Sunday, October 15, 2017 4:27:19 AM(UTC)
 
Hmm... it works fine on my side.
Make sure you are not missing this line.
Code:

e.Handled = true;
Guest Posted: Monday, October 9, 2017 12:03:11 AM(UTC)
 
Good morning Paul Rayman,

I've tried your solution and it's way better than the solution we were working on (the zoom doesn't focus on the left side of the screen anymore).
But it's not very accurate. I mean that it doesn't zoom exactly on the cursor position.
Do I have to put the cursor position in the ScrollToPoint function? ( pdfViewer1.ScrollToPoint(idx, "someting that represent the cursor position"); )

Thank you very much !
Paul Rayman Posted: Monday, October 2, 2017 5:41:32 AM(UTC)
 
I am assuming that you are looking for a WPF solution and if so, try the following code example

Code:

private void pdfViewer1_MouseWheel(object sender, MouseWheelEventArgs e)
{
	if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
	{
		e.Handled = true;

		int idx = pdfViewer1.CurrentIndex;
		var mousePoint = e.GetPosition(this);
		var leftTopPagePoint = pdfViewer1.ClientToPage(idx, new Point(0, 0));
		var pagePoint = pdfViewer1.ClientToPage(idx, mousePoint);

		if (e.Delta < 0 && pdfViewer1.Zoom > 0.4)
			pdfViewer1.Zoom /= 1.3f;
		else if (e.Delta > 0)
			pdfViewer1.Zoom *= 1.3f;
		pdfViewer1.SizeMode = SizeModes.Zoom;

		var newPagePoint = pdfViewer1.ClientToPage(idx, mousePoint);
		var offsetPoint = newPagePoint - pagePoint;

		var scrollPoint = leftTopPagePoint - offsetPoint;

		// Scroll the page point into view
		pdfViewer1.ScrollToPoint(idx, scrollPoint);
	}

}
Guest Posted: Friday, September 29, 2017 4:03:39 PM(UTC)
 
Hello,
I can see that this subject is a bit old (it a ex coworker who started it).

I'm now facing the same problem and there is noting clear about this on the web.
The problem is that I'm not able to make a correct MousseWeel Zoom on my PdfViewer. It goes to the top left side of my window instead of focusing on the cursor.
I glad that someone answered but it doesn't seem to work for me. But I see that you use the method PdfViewer.ScrollToPoint(). Is this the solution of my problem ?

Is there someone here who may have something for me to work with?


Thank you very much.
slat Posted: Tuesday, April 18, 2017 5:14:27 AM(UTC)
 
Not sure on the WPF implementation but I have been able to achieve this in Winforms. (Although its a bit sloppy).

Code:

// Cache a copy of the current mouse position on page
var pagePoint = pdfViewer1.ClientToPage(_pdfViewer.CurrentIndex, 
    pdfViewer1.PointToClient(Cursor.Position));

// Set the zoom
pdfViewer1.Zoom = zoom;
pdfViewer1.SizeMode = SizeModes.Zoom;

// Copy page point back to new client relative position
var clientPoint = pdfViewer1.PageToClient(pdfViewer1.CurrentIndex, pagePoint);

var size = pdfViewer1.ClientSize;

// Set client point to half the viewer size (To place point in middle of page)
clientPoint.X -= size.Width / 2;
clientPoint.Y -= size.Height / 2;

// Set point back to page again
pagePoint = pdfViewer1.ClientToPage(pdfViewer1.CurrentIndex, clientPoint);

// Scroll the page point into view
pdfViewer1.ScrollToPoint(pdfViewer1.CurrentIndex, pagePoint);


It does jitter a bit, as the layout is recalculated during the zoom and again on applying the scroll to point afterwards.
Seems like some changes may be required here: (Not sure?)
https://github.com/Patagames/Pdf.WinForms/blob/master/PdfViewer.cs#L1439

I also added this code to the top of the OnMouseWheel method: (As the main form uses ctrl key + mouse wheel to initiate scroll)
https://github.com/Patagames/Pdf.WinForms/blob/master/PdfViewer.cs#L1657
Code:

if ((ModifierKeys & Keys.Control) == Keys.Control)
{
    base.OnMouseWheel(e);
    return;
}


Would appreciate any insight into preventing the jittering, ie. delaying layout until the very end.
Guest Posted: Wednesday, March 29, 2017 4:31:17 AM(UTC)
 
Hi guys !

I would like to zoom with MouseWheel (Delta > 0) or (Delta < 0) at Cursor Mouse position on PdfViewer.
I used Pdfium.NET.SDK 3.7.4.2704 (latest version on February 2017)

How to make this in C# ?

Code:

<Grid Panel.ZIndex="1" Grid.Column="1" Grid.ColumnSpan="2"  Grid.Row="3"  Grid.RowSpan="2" x:Name="ScroolBar" >
    <ScrollViewer x:Name="viewerScroll" Panel.ZIndex="3" CanContentScroll="True"  VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
        <Wpf:PdfViewer x:Name="pdfViewer"  MouseWheel="pdfViewer_MouseWheel" MouseMove="pdfViewer_MouseMove"  Background="#AAA095" >
        </Wpf:PdfViewer>
    </ScrollViewer>
</Grid>



Code:

private void pdfViewer_MouseWheel(object sender, MouseWheelEventArgs e)
{
    System.Windows.Point p = e.GetPosition(null);

    //float newzoom = this.pdfViewer.Zoom;
    //this.pdfViewer.PageToClient(this.pdfViewer.CurrentIndex, p);

    if (e.Delta > 0)
    {
        calculZoomPlus();
    }
    else if(e.Delta < 0)
    {
        calculZoomMoins();
    }
}

private void calculZoomPlus()
{
    if (this.pdfViewer.Zoom < 0.125f)
    {
        this.pdfViewer.Zoom = 0.125f;
    }
    else if (this.pdfViewer.Zoom >= 0.125f && this.pdfViewer.Zoom < 4.00f)
    {
        this.pdfViewer.Zoom += 0.125f;
    }
    else if (this.pdfViewer.Zoom == 4.00f)
    {
        this.pdfViewer.Zoom = 4.00f;
    }
}

private void calculZoomMoins()
{
    if (this.pdfViewer.Zoom == 0.25f)
    {
        this.pdfViewer.Zoom = 0.125f;
    }
    else if (this.pdfViewer.Zoom <= 0.125f)
    {
           
    }
    else if (this.pdfViewer.Zoom > 0.125f && this.pdfViewer.Zoom <= 4.00f)
    {
        this.pdfViewer.Zoom -= 0.125f;
    }
}



Sorry for my bad english, I'm french.

Thanks for your help.