How to get correct PTPDFRect for a PTField customly created on a pdf view.

Good day

I want to know on how to get correct coordinates if you creating a field on a pdf using PTField for iOS.
I’m detecting my coordinates using CGPoint to get an X and Y, so I could create my own box with a width and height of 200 each.

I want to get the coordinates based on where I tapped with my finger on the pdf view.

Please see the code below.

PTField *field = [[_pdfViewCtrl GetDoc] FieldCreate:@“MySignature” type:e_ptsignature field_value:nil];
PTPage *page = [[_pdfViewCtrl GetDoc] GetPage:[_pdfViewCtrl GetCurrentPage]];

CGPoint point = [gesture locationInView:_pdfViewCtrl];
PTPDFRect *rect = [[PTPDFRect alloc] initWithX1:point.x y1:point.y x2:50 y2:50];

PTWidget *wigdget = [PTWidget Create:[[_pdfViewCtrl GetDoc] GetSDFDoc] pos:rect field:field];
PTPage *page = [[_pdfViewCtrl GetDoc] GetPage:[_pdfViewCtrl GetCurrentPage]];

[page AnnotPushBack:wigdget];
[wigdget SetPage:page];

PTObj *obj = [wigdget GetSDFObj];
[obj PutNumber:@“F” value:132];
[obj PutName:@“Type” name:@“Annot”];

Thank you.

The CGPoint you get from the OS is in screen coordinates, so you need to convert to PDF page coordinates to work with the PDF.

So to convert point from screen to PDF page call the following.

[self ConvertScreenPtToPagePtX:&point.x Y:&point.y PageNumber:pageNumber];

And then call the following

`
PTPDFRect *rect = [[PTPDFRect alloc] initWithX1:point.x y1:point.y x2:point.x + 200 y2:point.y + 200]; // for 200x200 field

`

Also, looks like you are missing call to

[page AnnotPushBack:widget];

Please look at the CreateToolBase.m onTouchesEnded method to see how this is done, including the very important step of locking the document for modification.

Hi Ryan

Thanks a lot for the response. It works well.

I just need to adjust my calculations again as this works well when creating a field in the middle of the pdf screen view, but if i can tap towards the edge of the screen, it adjust it to too far to the middle.

Thank you for the help. Much appreciation .