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
nobody  
#1 Posted : Monday, July 6, 2020 5:52:18 AM(UTC)
Quote
nobody

Rank: Newbie

Groups: Registered
Joined: 7/6/2020(UTC)
Posts: 3
Czech Republic
Location: Prague

Thanks: 1 times
Hi there,

I've been trying to figure out how to add a custom shape (like a zone, which purpose is highliting the selected place) on the pdf page in WPF.
It's easy to do it in WinForms using PdfViewer.OnPaint method, but there is nothing like that in WPF if I'm right and please correct me if not.

Therefore I've tried a numerous ways and did it by adding a shape in a grid or canvas which is fine, but the problem occured when started zooming the page.
I used the methods such as PdfViewer.CalcActualRect etc. to get the coords of the page rect, then a difference between the shape rect and page rect and so on, but it still doesn't scale properly when zooming the page or resizing a window.

Is there any way how to bound the shape's size to the page (its content)?
Or can you explain me a bit how it works please?
I would really appreciate it!

Thanks
Paul Rayman  
#2 Posted : Tuesday, July 7, 2020 8:43:26 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 3 times
Was thanked: 110 time(s) in 107 post(s)
Originally Posted by: nobody Go to Quoted Post
I've been trying to figure out how to add a custom shape (like a zone, which purpose is highliting the selected place) on the pdf page in WPF.
It's easy to do it in WinForms using PdfViewer.OnPaint method, but there is nothing like that in WPF if I'm right and please correct me if not.


PdfViewer.OnRender

Quote:

Is there any way how to bound the shape's size to the page (its content)?


Try ClientToPage / PageToClient to translate point between the coordinate space of the page and the control.

Edited by user Tuesday, July 7, 2020 8:48:02 AM(UTC)  | Reason: Not specified

nobody  
#3 Posted : Thursday, July 9, 2020 7:13:54 AM(UTC)
Quote
nobody

Rank: Newbie

Groups: Registered
Joined: 7/6/2020(UTC)
Posts: 3
Czech Republic
Location: Prague

Thanks: 1 times
Quote:
PdfViewer.OnRender

Don't exactly know how to use this, but it won't be necessary I guess as I don't wanna draw the rectangle on the page directly. I would prefer to use like another layer and that's why I've been trying to use a canvas or grid instead, but thanks anyway. Maybe I'll try later on...

Quote:
Try ClientToPage / PageToClient to translate point between the coordinate space of the page and the control.

In this case if I use PageToClient method, it seems to be the same as CalcActualRect meaning, that I can get these values from the CalcActualRect. I haven't got a lot of experience with such a computing so I might be wrong or just don't know how to use it properly.
Could you lead me more please?

Thanks!
Paul Rayman  
#4 Posted : Thursday, July 9, 2020 8:05:26 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 3 times
Was thanked: 110 time(s) in 107 post(s)
Call ClientToPage before scaling to find out the coordinates of your point in the page coordinate space.
After scaling, call PageToclient to find out the new coordinates of your point in the coordinate space of the control.
Now you can draw this point in any WPF-specific way. And this point will be in the same place as before relative to the page elements.

The coordinates of the point in the page coordinate space are the same regardless of the scale or rotation of the page.

Edited by user Thursday, July 9, 2020 8:08:20 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Paul Rayman for this useful post.
nobody on 7/10/2020(UTC)
nobody  
#5 Posted : Friday, July 10, 2020 7:45:54 AM(UTC)
Quote
nobody

Rank: Newbie

Groups: Registered
Joined: 7/6/2020(UTC)
Posts: 3
Czech Republic
Location: Prague

Thanks: 1 times
Works like a charm, thanks a lot again!
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.