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

Notification

Icon
Error

Options
Go to last post Go to first unread
thanghv  
#1 Posted : Saturday, March 23, 2019 5:26:47 AM(UTC)
thanghv

Rank: Newbie

Groups: Registered
Joined: 3/20/2019(UTC)
Posts: 6
Viet Nam
Location: HaNoi

Thanks: 2 times
Hello everyone,

I'm a new member and also new programmer c #, I had trouble switching from a RectangleF to Rectangle

On the viewing screen, I clicked e to drag the mouse to make a rectangle and took the position to attach a digital signature, when I dragged the mouse I got the position type RectangleF, but my signature library(ItextSharp) use type Rectangle. . How to convert position selection when drag the mouse and position signature is aligned correctly?

I consulted and used the rectangular mouse drag in this article:
https://forum.patagames....hot-feftality-as-Acrobat

Quote:

PointF lt;
PointF rb;
NormalizeSnapshotPoints(out lt, out rb);
//The rectangle on a page in PDF coordinates which should be snapshoted.
float pageX = lt.X;
float pageY = lt.Y;
float pageW = rb.X - lt.X;
float pageH = lt.Y - rb.Y;

Rectangle rect = new Rectangle((int)pageX, (int)pageY, (int)pageW, (int)pageH);

If converting directly to int as above, it will be skewed

Sorry,my English is very bad, looking forward to receiving everyone's help. Thanks so much

Edited by user Saturday, March 23, 2019 5:36:33 AM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Saturday, March 23, 2019 9:13:21 AM(UTC)
Paul Rayman

Rank: Administration

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

Thanks: 1 times
Was thanked: 85 time(s) in 84 post(s)
Hi,

lt and rb in the code you provided is a left-top and right-bottom corner of the rectangle in PDF points in user space coordinate system.
In the PDF documents, the origin of default user space always corresponds to the lowerleft corner of the page.

The contents of a page ultimately appear on a raster output device such as a display or a printer. Such devices vary greatly in the built-in coordinate systems they use to address pixels within their imageable areas. A particular device’s coordinate system is called its device space.
For the monitor the origin corresponds to the topleft corner of the screen.

I don't know what exactly means the Rectangle in the iTextSharp, but seems you need convert both lt and rb from one coordinate system to another. Given that you need integer coordinates, then most likely these are coordinates on the target device (monitor?)

Without knowing the details of your project it is extremely difficult to advise something specific.
thanks 1 user thanked Paul Rayman for this useful post.
thanghv on 3/24/2019(UTC)
thanghv  
#3 Posted : Sunday, March 24, 2019 11:09:48 PM(UTC)
thanghv

Rank: Newbie

Groups: Registered
Joined: 3/20/2019(UTC)
Posts: 6
Viet Nam
Location: HaNoi

Thanks: 2 times
Hi Paul,

Thank you for sharing, my project is similar to Adobe reader DC, when users open the file on pdfviewer, users will choose the location to attach the digital signature to that pdf file by drawing a rectangle to locate the signature location.

Below is my demo project
Step1: open file
step2: click drawing -> mouse down, hover to draw
step3: click sign

Link project :https://drive.google.com/file/d/1e7LEL-_FOLzop9jAwLhQMxUIFYrtG7Q5/view?usp=sharing

My problem as mentioned above, I cannot get the exact position that the user draws on pdfviewer, you can run my project and see that after signing the signature position, it is deviated from drawing.
I hope to receive your help, plz. Thanks
thanghv  
#4 Posted : Wednesday, March 27, 2019 10:26:47 PM(UTC)
thanghv

Rank: Newbie

Groups: Registered
Joined: 3/20/2019(UTC)
Posts: 6
Viet Nam
Location: HaNoi

Thanks: 2 times
plz! help me
Paul Rayman  
#5 Posted : Thursday, March 28, 2019 7:09:17 AM(UTC)
Paul Rayman

Rank: Administration

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

Thanks: 1 times
Was thanked: 85 time(s) in 84 post(s)
try to use pdfViewer1.PageToClient method to convert point from page coordinate space to user control coordinate space.
thanghv  
#6 Posted : Thursday, March 28, 2019 11:04:27 PM(UTC)
thanghv

Rank: Newbie

Groups: Registered
Joined: 3/20/2019(UTC)
Posts: 6
Viet Nam
Location: HaNoi

Thanks: 2 times
I did the drawing with pdfViewer1.PageToClient, you can look at my project, but it doesn't seem to be the location I need to identify the signature on the page. :(
thanghv  
#7 Posted : Wednesday, April 3, 2019 11:23:42 PM(UTC)
thanghv

Rank: Newbie

Groups: Registered
Joined: 3/20/2019(UTC)
Posts: 6
Viet Nam
Location: HaNoi

Thanks: 2 times
I tried every way I thought but I still couldn't solve the problem, could you please give me detailed instructions.

Edited by user Thursday, April 4, 2019 12:06:26 AM(UTC)  | Reason: Not specified

Paul Rayman  
#8 Posted : Thursday, April 4, 2019 10:29:30 AM(UTC)
Paul Rayman

Rank: Administration

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

Thanks: 1 times
Was thanked: 85 time(s) in 84 post(s)
Hi,

Use the following rect instead of yours
Code:
Rectangle rect = new Rectangle((int)pageX, (int)pageY - (int)pageH, (int)pageW, (int)pageH);

Also use SignaturePosition to align the signature in the rectangle.
thanks 1 user thanked Paul Rayman for this useful post.
thanghv on 4/5/2019(UTC)
thanghv  
#9 Posted : Friday, April 5, 2019 3:48:35 AM(UTC)
thanghv

Rank: Newbie

Groups: Registered
Joined: 3/20/2019(UTC)
Posts: 6
Viet Nam
Location: HaNoi

Thanks: 2 times
Originally Posted by: Paul Rayman Go to Quoted Post
Hi,

Use the following rect instead of yours
Code:
Rectangle rect = new Rectangle((int)pageX, (int)pageY - (int)pageH, (int)pageW, (int)pageH);

Also use SignaturePosition to align the signature in the rectangle.


Great, thank you so much!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.