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)
Paul Rayman Posted: Wednesday, June 27, 2018 1:10:13 AM(UTC)
 
bb code tags


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

vg_drengen Posted: Tuesday, June 26, 2018 11:46:23 PM(UTC)
 
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 Posted: Tuesday, June 26, 2018 8:19:38 AM(UTC)
 
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 Posted: Friday, June 22, 2018 1:09:29 AM(UTC)
 
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