Adding subviews to a PDFView

  • Hi,

    I use a PDFView to show PDF documents. I need to add an NSTextView as
    a subview of its documentView to provide editing capabilities (and
    using an annotation text widget won't cut it unfortunately). However,
    the view coordinates that convertRect:fromPage: provides return
    coordinates relative to the PDFView itself, not to its underlying
    documentView, so I know of no way to obtain the correct offset for the
    target page. Further, when zooming the PDFView, the NSTextView won't
    scale along. It remains at constant size. This is surprising since I
    would have thought the documentView or one of its superviews to be
    scaled, but apparently, this is not the case and it looks rather like
    something below the documentView is scaled.

    I tried adding the text view as a subview of the PDFView directly, and
    that allows me to place it on the correct page, and it all functions
    perfectly fine until the PDFView either gets zoomed or scrolled. The
    NSTextView will neither zoom nor scroll.

    So that begs the question:
    What is the correct way to add subviews to a PDFView such that they
    can be correctly positioned, and will zoom and scroll along with their
    superView(s)?
    If there is no proper way to do it, any hints as to how to hack my way
    around it? I could live with a solution that creates direct subview's
    of the PDFView as long as I can make them scale and scroll along with
    the view's contents.

    -António

    ----------------------------------------------------
    It is better to light a candle than to curse the darkness
    ----------------------------------------------------
  • Hi Antonio,

    There is a (10.5) sample program called PDFView Subclasser that “shows you how
    to subclass PDFView in order to overlay content relative to the PDF content.”
    It uses a new 10.5 PDFView method drawPagePost.

    That may help you do what you need to do.

    Sincerely,
    Joel

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • On 12 Nov 2007, at 17:46, Joel Norvell wrote:

    > There is a (10.5) sample program called PDFView Subclasser that
    > “shows you how
    > to subclass PDFView in order to overlay content relative to the PDF
    > content.”
    > It uses a new 10.5 PDFView method drawPagePost.
    >
    > That may help you do what you need to do.

    <embarrassed-blush-on-cheeks>Duh, I know that example. What was I
    thinking?! At any rate I was not remembering to look for anything in
    the example project. I'll play around with this. Should get me there.</
    embarrassed-blush-on-cheeks>

    Thanks,
    Antonio

    --------------------------------------------------------
    Today you are You, that is truer than true.
    There is no one alive who is Youer than You.
    Today I am Me, and I am freer than free.
    There is no one alive who is Me-er than Me.
    I am the BEST I can possibly be.

    --Dr. Seuss
    --------------------------------------------------------
  • On Nov 11, 2007, at 11:42 AM, Antonio Nunes wrote:
    > I use a PDFView to show PDF documents. I need to add an NSTextView
    > as a subview of its documentView to provide editing capabilities
    > (and using an annotation text widget won't cut it unfortunately).
    > However, the view coordinates that convertRect:fromPage: provides
    > return coordinates relative to the PDFView itself, not to its
    > underlying documentView, so I know of no way to obtain the correct
    > offset for the target page.

    You can convert from the page to the PDFView and vice versa using
    PDFView methods.  You can get the embedded documentView from PDFView.
    The missing piece is the ol' -[NSView convertPointFrom/ToView:] methods.

    In short, you need to do a double convert.  page->PDFView and then
    PDFView->documentView.

    john calhoun—
  • On 14 Nov 2007, at 19:54, John Calhoun wrote:

    > You can convert from the page to the PDFView and vice versa using
    > PDFView methods.  You can get the embedded documentView from
    > PDFView.  The missing piece is the ol' -[NSView convertPointFrom/
    > ToView:] methods.
    >
    > In short, you need to do a double convert.  page->PDFView and then
    > PDFView->documentView.

    Thanks John,

    I figured that out after Joell's post. It was just a one-liner to add
    to what I already had. I also solved the issue of the text view not
    scaling along with it's superview(s), so now we have a happy and well
    behaved text editor within a PDFView. :-)

    Cheers,
    António

    -----------------------------------------------------------
    Some things have to be believed to be seen.

    --Ralph Hodgson
    -----------------------------------------------------------
  • Hi,

    I do have Leopard and access to the Leopard dev center but can't find
    this particular sample, where would I find it?
    Thanks,
    Alex

    > Hi Antonio,
    >
    > There is a (10.5) sample program called PDFView Subclasser that
    > shows you how
    > to subclass PDFView in order to overlay content relative to the PDF
    > content.
    > It uses a new 10.5 PDFView method drawPagePost.
    >
    > That may help you do what you need to do.
    >
    > Sincerely,
    > Joel
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today