• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: PDFKit: translate point coordinates from view coordinates into page coordinates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PDFKit: translate point coordinates from view coordinates into page coordinates


  • Subject: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
  • From: Nick <email@hidden>
  • Date: Tue, 27 Mar 2012 15:29:48 +0300

Hi Alvaro
Thank you for the response!
Yes, this is it. I just found a sample code PDFKitLinker2, and it
showed how to do just what i need.


27 марта 2012 г. 15:05 пользователь Alvaro Costa Neto
<email@hidden> написал:
> Hey Nick, how are you?
>
> Try to use the PDFView's convertPoint/Rect:to/fromPage: methods <http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/QuartzFramework/Classes/PDFView_Class/Reference/Reference.html>. The trick is to always remember to use a common ground (the PDFView itself in this case) before converting to/from page coordinates. I don't know if the convert methods take scale factor into account, but I believe they do.
>
> Best regards,
> Alvaro Costa Neto
>
> Em 27/03/2012, às 08:19, Nick escreveu:
>
>> Hello
>>
>> I would like to place a PDFAnnotation onto a PDF page in a place where
>> the user clicked with the mouse.
>> Position for PDFAnnotations is specified using "page coordinates".
>> Mouse position - using global coordinates, which can be translated
>> into PDFView coordinates. However, I can't figure out how to translate
>> view coordinates into page coordinates correctly. Here's what  I am
>> doing:
>>
>>       NSPoint locationInView = [self convertPoint:[theEvent
>> locationInWindow] fromView:[[self window] contentView]];
>>       NSPoint locationOnPage = [self convertPoint:locationInView fromView:self];
>>       float scaleFactor = 1/[self scaleFactor];
>>       locationOnPage = NSMakePoint((locationOnPage.x)*scaleFactor,
>> (locationOnPage.y)*scaleFactor);
>>
>> This locationOnPage contains correct values (i.e., the annotation is
>> placed where the mouse button was clicked) only if the zooming was
>> 100%, and view boundaries exactly matched page boundaries (as shown on
>> the picture: http://rghost.net/37251215/image.png).
>> However, if the page is zoomed in/out, and does not exactly occupy the
>> whole PDFView space (http://rghost.net/37251118/image.png) I do not
>> get right coordinates: when I click in the bottom left corner of the
>> PDFView, i see annotation appear in the bottom left corner of the
>> page, which is not even on the page..
>>
>> How could I do this right?
>> All I need is the page origin position on the view, but there's no
>> such a method, as it seems..
>>
>> Thank you
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >PDFKit: translate point coordinates from view coordinates into page coordinates (From: Nick <email@hidden>)
 >Re: PDFKit: translate point coordinates from view coordinates into page coordinates (From: Alvaro Costa Neto <email@hidden>)

  • Prev by Date: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
  • Next by Date: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Previous by thread: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
  • Next by thread: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
  • Index(es):
    • Date
    • Thread