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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
vg_drengen  
#1 Posted : Friday, June 22, 2018 4:09:29 AM(UTC)
Quote
vg_drengen

Rank: Newbie

Groups: Registered
Joined: 6/22/2018(UTC)
Posts: 2
Denmark
Location: Aalborg

Hi

I have a PDF Size A3 viewed in Landscape, where I need to Zoom and scroll to a specific point. The zooming to 400% works OK, but the scrolling, I just can't get to work.

The PDF is created in AutoCAD, don't know if that is of an significance.

Size A3 is 420x297 mm, in points I get these numbers from debug (page width and height) 1191 x 842, and that is consistent with a point being 1/72 of an inch.

Can anyone tell me, if I want to zoom to e.g. the very middle of this pdf, what X and Y should I call with?:

PointF pnt = new PointF(X, Y);
pdfViewer.ScrollToPoint(0, pnt);

Prior to the above, I do this:
pdfViewer.SizeMode = SizeModes.Zoom;
pdfViewer.PageAlign = ContentAlignment.MiddleCenter;
pdfViewer.Padding = new System.Windows.Forms.Padding(0, 0, 0, 0);
pdfViewer.Zoom = zoomFactor;

It just doesn't zoom to the middle of the page.

Regards

Paul Rayman  
#2 Posted : Tuesday, June 26, 2018 11:19:38 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,003

Thanks: 5 times
Was thanked: 121 time(s) in 118 post(s)
X and Y must be in the page coordinate system. That is, in PDF points.
Please take a look at the code below. The code illustrates how to zoom and scroll to the center of the page.

Code:

            float x = pdfViewer1.CurrentPage.Width / 2;
            float y = pdfViewer1.CurrentPage.Height / 2;
            pdfViewer1.SizeMode = SizeModes.Zoom;
            pdfViewer1.Zoom = 4;
            pdfViewer1.ScrollToPoint(0, new PointF(x, y));


Please note - the center of the page will be in the left top corner of the viewer control.
ScrollToPoint scrolls content to in the following manner - specified point placed on the left top corner. So if you want to place the center of the page in the center of the viewport, then you need to calculate the correction.

You may found very similar example here
https://forum.patagames....or-Position-on-PdfViewer

Hope it helps you to understand how to calculate correction.
vg_drengen  
#3 Posted : Wednesday, June 27, 2018 2:46:23 AM(UTC)
Quote
vg_drengen

Rank: Newbie

Groups: Registered
Joined: 6/22/2018(UTC)
Posts: 2
Denmark
Location: Aalborg

Yes, I actually figured it out.

What I did was to create a handler for mouse double click, and then I clicked in the corners of the pdf and converted the mouse coordinates to page coordinates through:

PointF pagePeek = pdfViewer.ClientToPage(0, clientPoint);

I was surprised as to where 0,0 and thus the axist orientation were (I am viewing Landscape A3 PDF's created in AutoCAD)

So her is what I did:

pdfViewer.SizeMode = SizeModes.Zoom;
pdfViewer.Padding = new System.Windows.Forms.Padding(0, 0, 0, 0);
pdfViewer.Zoom = zoomFactor;

PointF pntPagePointToBeCenteredInViewer = new PointF(pagePointsX, pagePointsY);

// ScrollToPoint seems to just scroll the point into view, then stop.
// In order to center the point in the viewer, we shift the coordinates half the width of the viewer:
Point clientPoint = pdfViewer.PageToClient(0, pntPagePointToBeCenteredInViewer);
clientPoint.X -= pdfViewer.ClientSize.Width / 2;
clientPoint.Y -= pdfViewer.ClientSize.Height / 2;

PointF pagePointScrollTarget = pdfViewer.ClientToPage(0, clientPoint);
pdfViewer.ScrollToPoint(0, pagePointScrollTarget);

BTW: What are you using to get these nice "screenshots" with black background?
Paul Rayman  
#4 Posted : Wednesday, June 27, 2018 4:10:13 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,003

Thanks: 5 times
Was thanked: 121 time(s) in 118 post(s)
bb code tags


Code:
[code=cs]
// code placed here
[/сode]

Quick Reply Show Quick Reply
Users browsing this topic
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.