Mac Developer Library

Developer

PDFKit Reference Collection PDFView Class Reference

Options
Deployment Target:

On This Page
Language:

PDFView

A PDFView object encapsulates the functionality of PDF Kit into a single widget that you can add to your application using Interface Builder.

PDFView may be the only class you need to deal with for adding PDF functionality to your application. It lets you display PDF data and allows users to select content, navigate through a document, set zoom level, and copy textual content to the Pasteboard. PDFView also keeps track of page history.

You can subclass PDFView to create a custom PDF viewer.

You can also create a custom PDF viewer by using the PDF Kit utility classes directly and not using PDFView at all.

  • Returns the document associated with a PDFView object.

    Declaration

    - (PDFDocument *)document

    Availability

    Available in OS X v10.4 and later.

  • Associates a document with a PDFView object.

    Declaration

    - (void)setDocument:(PDFDocument *)document

    Discussion

    If a document was already associated with the view, it is released first and then document is associated with the view.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – document

  • Returns a Boolean value indicating whether the user can navigate to the previous page in the page history.

    Declaration

    - (BOOL)canGoBack

    Discussion

    The page history gets built as your application calls navigation methods such as goToDestination: and goToLastPage:.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – goBack:

  • Returns a Boolean value indicating whether the user can navigate to the next page in the page history.

    Declaration

    - (BOOL)canGoForward

    Discussion

    The page history gets built as your application calls navigation methods such as goToDestination: and goToLastPage:.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – goForward:

  • Returns a Boolean value indicating whether the user can navigate to the first page of the document.

    Declaration

    - (BOOL)canGoToFirstPage

    Discussion

    The return value will be YEStrue unless the view is already displaying the first page.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the user can navigate to the last page of the document.

    Declaration

    - (BOOL)canGoToLastPage

    Discussion

    The return value will be YEStrue unless the view is already displaying the last page.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the user can navigate to the next page of the document.

    Declaration

    - (BOOL)canGoToNextPage

    Discussion

    The return value will be YEStrue unless the view is displaying the last page.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the user can navigate to the previous page of the document.

    Declaration

    - (BOOL)canGoToPreviousPage

    Discussion

    The return value will be YEStrue unless the view is displaying the first page.

    Availability

    Available in OS X v10.4 and later.

  • Returns the current page.

    Declaration

    - (PDFPage *)currentPage

    Discussion

    When there are two pages in the view in a two-up mode, “current page” is the left page. For continuous modes, returns the page crossing a horizontal line halfway between the view’s top and bottom bounds.

    Availability

    Available in OS X v10.4 and later.

  • Returns a PDFDestination object representing the current page and the current point in the view specified in page space.

    Declaration

    - (PDFDestination *)currentDestination

    Discussion

    Page space is a 72 dpi coordinate system with the origin at the lower-left corner of the current page.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – currentPage
    – goToDestination: (PDFDestination)

  • Navigates back one step in the page history.

    Declaration

    - (IBAction)goBack:(id)sender

    Discussion

    The page history gets built as your application calls navigation methods such as goToDestination: and goToLastPage:.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – canGoBack

  • Navigates forward one step in the page history.

    Declaration

    - (IBAction)goForward:(id)sender

    Discussion

    The page history gets built as your application calls navigation methods such as goToDestination: and goToLastPage:.

    Availability

    Available in OS X v10.4 and later.

  • Navigates to the first page of the document.

    Declaration

    - (IBAction)goToFirstPage:(id)sender

    Discussion

    PDF Kit records the move in its page history.

    Availability

    Available in OS X v10.4 and later.

  • Navigates to the last page of the document.

    Declaration

    - (IBAction)goToLastPage:(id)sender

    Discussion

    PDF Kit records the move in its page history.

    Availability

    Available in OS X v10.4 and later.

  • Navigates to the next page of the document.

    Declaration

    - (IBAction)goToNextPage:(id)sender

    Discussion

    PDF Kit records the move in its page history.

    Availability

    Available in OS X v10.4 and later.

  • Navigates to the previous page of the document.

    Declaration

    - (IBAction)goToPreviousPage:(id)sender

    Discussion

    PDF Kit records the move in its page history.

    Availability

    Available in OS X v10.4 and later.

  • Scrolls to the specified page.

    Declaration

    - (void)goToPage:(PDFPage *)page

    Discussion

    PDF Kit records the move in its page history.

    Availability

    Available in OS X v10.4 and later.

  • Navigates to the specified destination.

    Declaration

    - (void)goToDestination:(PDFDestination *)destination

    Discussion

    Destinations include a page and a point on the page specified in page space.

    Page space is a 72 dpi coordinate system with the origin at the lower-left corner of the current page.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – currentDestination (PDFDestination)
    – currentPage

  • Scrolls to the first character of the specified selection.

    Declaration

    - (void)goToSelection:(PDFSelection *)selection

    Discussion

    PDF Kit records the move in its page history.

    Availability

    Available in OS X v10.4 and later.

  • Navigates to the specified rectangle on the specified page.

    Declaration

    - (void)goToRect:(NSRect)rect onPage:(PDFPage *)page

    Discussion

    If the specified rectangle is already visible, this method does nothing. This allows you to scroll the PDFView object to a specific PDFAnnotation or PDFSelection object, because both of these objects have bounds methods that return an annotation or selection position in page space.

    Note that rect is specified in page-space coordinates. Page space is a 72 dpi coordinate system with the origin at the lower-left corner of the current page.

    Availability

    Available in OS X v10.5 and later.

  • Sets the display mode for the view.

    Declaration

    - (void)setDisplayMode:(PDFDisplayMode)mode

    Discussion

    Available display modes are single page, single-page continuous, two-up, and two-up continuous, as defined in Constants.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – displayMode

  • Returns the current display mode.

    Declaration

    - (PDFDisplayMode)displayMode

    Discussion

    See Constants for possible values.

    Availability

    Available in OS X v10.4 and later.

  • Toggles the display of page breaks.

    Declaration

    - (void)setDisplaysPageBreaks:(BOOL)breaks

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the view is displaying page breaks.

    Declaration

    - (BOOL)displaysPageBreaks

    Availability

    Available in OS X v10.4 and later.

  • Specifies the box to display and to clip to.

    Declaration

    - (void)setDisplayBox:(PDFDisplayBox)box

    Discussion

    The values for box are defined in the PDFDisplayBox enumeration. The default value for this method is kPDFDisplayBoxCropBox.

    The available values for display boxes are defined in the Constants section in the PDFPage class.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – displayBox

  • Returns the current style of display box.

    Declaration

    - (PDFDisplayBox)displayBox

    Discussion

    The available values for display boxes are defined in the Constants section in the PDFPage class.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the view will display the first page as a book cover (meaningful only when the document is in two-up or two-up continuous display mode).

    Declaration

    - (BOOL)displaysAsBook

    Availability

    Available in OS X v10.4 and later.

  • Specifies whether the view should treat the document’s first page as a book cover.

    Declaration

    - (void)setDisplaysAsBook:(BOOL)asBook

    Discussion

    For two-up modes, a YEStrue value for this method specifies that the first page should be displayed by itself.

    Availability

    Available in OS X v10.4 and later.

  • Specifies whether to use anti-aliasing in the view.

    Declaration

    - (void)setShouldAntiAlias:(BOOL)aliasing

    Discussion

    The default value is YEStrue.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the view is anti-aliased.

    Declaration

    - (BOOL)shouldAntiAlias

    Availability

    Available in OS X v10.4 and later.

  • Sets the greeking threshold to use for displaying text.

    Declaration

    - (void)setGreekingThreshold:(float)threshold

    Discussion

    The default threshold is 3.0.

    Availability

    Available in OS X v10.4 and later.

  • Returns the current greeking threshold for the view.

    Declaration

    - (float)greekingThreshold

    Availability

    Available in OS X v10.4 and later.

  • Sets the view’s background color to the specified color.

    Declaration

    - (IBAction)takeBackgroundColorFrom:(id)sender

    Discussion

    A view’s background is the area displayed to either side of a PDF document’s pages. The background also appears between pages when page breaks are enabled. The default color is a 50% gray.

    Availability

    Available in OS X v10.4 and later.

  • Sets the view’s background color.

    Declaration

    - (void)setBackgroundColor:(NSColor *)newColor

    Discussion

    A view’s background is the area displayed to either side of a PDF document’s pages. The background also appears between pages when page breaks are enabled. The default color is a 50% gray.

    Availability

    Available in OS X v10.4 and later.

  • Returns the view’s background color.

    Declaration

    - (NSColor *)backgroundColor

    Discussion

    A view’s background is the area displayed to either side of a PDF document’s pages. The background also appears between pages when page breaks are enabled. The default color is a 50% gray.

    Availability

    Available in OS X v10.4 and later.

  • Sets a delegate for the view.

    Declaration

    - (void)setDelegate:(id)anObject

    Availability

    Available in OS X v10.4 and later.

    See Also

    – delegate

  • Returns the view’s delegate.

    Declaration

    - (id)delegate

    Availability

    Available in OS X v10.4 and later.

  • Sets the scale factor for the view.

    Declaration

    - (void)setScaleFactor:(float)scale

    Discussion

    The default value is 1.0, corresponding to actual size.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – scaleFactor

  • Returns the current scale factor for the view.

    Declaration

    - (float)scaleFactor

    Availability

    Available in OS X v10.4 and later.

  • Zooms in by increasing the scaling factor.

    Declaration

    - (IBAction)zoomIn:(id)sender

    Discussion

    Each invocation of zoomIn muliplies the scaling factor by the square root of 2.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the user can magnify the view—that is, zoom in.

    Declaration

    - (BOOL)canZoomIn

    Availability

    Available in OS X v10.4 and later.

  • Zooms out by decreasing the scaling factor.

    Declaration

    - (IBAction)zoomOut:(id)sender

    Discussion

    Each invocation of zoomOut divides the scaling factor by the square root of 2.

    Availability

    Available in OS X v10.4 and later.

  • Returns a Boolean value indicating whether the user can view an expanded area—that is, zoom out.

    Declaration

    - (BOOL)canZoomOut

    Availability

    Available in OS X v10.4 and later.

  • Toggles whether the scaling factor applied to a view automatically responds to resizing.

    Declaration

    - (void)setAutoScales:(BOOL)newAuto

    Discussion

    When set to autoscaling, the document scales to fill the PDFView object as the user resizes it.

    For the single-page and two-up continuous modes, autoscaling fits the page to the width of the view. For single-page and two-up noncontinuous modes, autoscaling provides best fit, in which the viewed pages are as large as possible while displaying in their entirety within the view.

    Availability

    Available in OS X v10.4 and later.

    See Also

    – autoScales

  • Returns a Boolean value indicating whether autoscaling is set.

    Declaration

    - (BOOL)autoScales

    Availability

    Available in OS X v10.4 and later.

  • Returns the type of area the mouse cursor is over.

    Declaration

    - (PDFAreaOfInterest)areaOfInterestForMouse:(NSEvent *)theEvent

    Discussion

    The PDFAreaOfInterest enumeration defines the various area types. This method is for custom subclasses of the PDFView class. Use it if you override the NSResponder class’s mouseMoved: method or related methods.

    Refer to Constants for the various values of the area-of-interest constants. Each of these constants contributes to the value of the PDFAreaOfInterest bit field.

    Availability

    Available in OS X v10.4 and later.

  • Sets the type of mouse cursor according to the type of area the mouse cursor is over.

    Declaration

    - (void)setCursorForAreaOfInterest:(PDFAreaOfInterest)area

    Discussion

    This method is especially useful for custom subclasses of the PDFView class.

    Availability

    Available in OS X v10.4 and later.

  • Performs the specified action.

    Declaration

    - (void)performAction:(PDFAction *)action

    Availability

    Available in OS X v10.5 and later.

  • Returns the current selection.

    Declaration

    - (PDFSelection *)currentSelection

    Discussion

    Returns NULL if no selection exists.

    Note that this method returns the actual instance of the current PDFSelection object. Therefore, if you want to modify it, you should make a copy of the returned selection and modify that, instead.

    Availability

    Available in OS X v10.4 and later.

  • Sets the selection.

    Declaration

    - (void)setCurrentSelection:(PDFSelection *)selection

    Discussion

    The view redraws as necessary but does not scroll. If you need to scroll to the current selection, use scrollSelectionToVisible:. If you pass nil for the selection, this call is equivalent to calling clearSelection.

    Availability

    Available in OS X v10.4 and later.

  • Selects all text in the document.

    Declaration

    - (IBAction)selectAll:(id)sender

    Availability

    Available in OS X v10.4 and later.

  • Clears the selection.

    Declaration

    - (void)clearSelection

    Discussion

    The view redraws as necessary but does not scroll. This call is equivalent to calling [PDFView setCurrentSelection:NULL].

    Availability

    Available in OS X v10.4 and later.

  • Copies the text in the selection, if any, to the Pasteboard.

    Declaration

    - (void)copy:(id)sender

    Availability

    Available in OS X v10.4 and later.

  • Scrolls the view until the selection is visible.

    Declaration

    - (void)scrollSelectionToVisible:(id)sender

    Availability

    Available in OS X v10.4 and later.

  • Sets the selection, in an animated way, if desired.

    Declaration

    - (void)setCurrentSelection:(PDFSelection *)selection animate:(BOOL)animate

    Discussion

    This method behaves as setCurrentSelection:, but with the addition of animation, if animate is YEStrue. The animation serves to draw the user’s attention to the new selection, which can be useful when implementing search.

    Availability

    Available in OS X v10.5 and later.

  • Highlights the specified array of selections.

    Declaration

    - (void)setHighlightedSelections:(NSArray *)selections

    Discussion

    Unlike the selections users set (using, for example, setCurrentSelection:), the selections you specify in this method do not go away (that is, appear deselected) when users click elsewhere in the view or document. Instead, to deselect the selections, you must call [setHighlightedSelections:NULL] to remove them.

    You might use this method to highlight the set of matches from a text search. To prevent the user from confusing their own selections with selections you set using this method, it is recommended that you use a highlight color that is different from the user’s default text selection color.

    Availability

    Available in OS X v10.5 and later.

  • Returns the array of selections that are highlighted using setHighlightedSelections.

    Declaration

    - (NSArray *)highlightedSelections

    Availability

    Available in OS X v10.5 and later.

  • A convenience method that calls – [[self document] setpassword:] with the password from the specified sender.

    Declaration

    - (void)takePasswordFrom:(id)sender

    Availability

    Available in OS X v10.4 and later.

  • For use by subclasses of PDFView for custom rendering of pages.

    Declaration

    - (void)drawPage:(PDFPage *)page

    Discussion

    Do not invoke this method, except by invoking it on super from a subclass.

    The PDFView class calls drawPage: as necessary for each visible page that requires rendering. In the PDFView class, this method erases page to white, calls [page drawInRect: pageRect withBox: [self displayBox]] , and then draws the selection, if any.

    You can override this method to draw on top of a PDF page or to control how pages are drawn. In these cases, invoke this method on super and then perform custom drawing on top of the PDF page.

    Availability

    Available in OS X v10.4 and later.

  • For use by subclasses of PDFView for post-page rendering.

    Declaration

    - (void)drawPagePost:(PDFPage *)page

    Discussion

    The default implementation of this method draws the text highlighting (if any) for the page. This method does not apply scaling or rotating to the current context to map to page space; instead, the context is in view-space coordinates (in which the origin is at the lower-left corner of the current PDF view).

    Availability

    Available in OS X v10.5 and later.

  • Prints the document with the specified printer information.

    Declaration

    - (void)printWithInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate

    Discussion

    If autoRotate is set to YEStrue, then ths method ignores the orientation attribute in the NSPrintInfo object and instead chooses the orientation that best fits the page to the paper size. This orientation occurs on a page-by-page basis.

    Availability

    Available in OS X v10.4 and later.

  • Prints the document with the specified printer and page-scaling information.

    Declaration

    - (void)printWithInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate pageScaling:(PDFPrintScalingMode)scale

    Discussion

    If pageScaling is set to kPDFPrintPageScaleToFit, each page is scaled up or down to best fit the paper size. If pageScaling is set to kPDFPrintPageScaleDownToFit, only large pages are scaled down to fit; small pages are not scaled up to fit. Specifying kPDFPrintPageScaleNone for pageScaling is equivalent to calling printWithInfo:autoRotate:. See PDFDocument for more information on page-scaling types.

    Availability

    Available in OS X v10.5 and later.

  • Returns the innermost view used by PDFView or by your PDFView subclass.

    Declaration

    - (NSView *)documentView

    Discussion

    The innermost view is the one displaying the visible document pages. This method is useful when converting coordinates from one view to another.

    Availability

    Available in OS X v10.4 and later.

  • Returns the size needed to display a row of the current document page.

    Declaration

    - (NSSize)rowSizeForPage:(PDFPage *)page

    Discussion

    The size is dependent on the current scale factor and display attributes.

    Availability

    Available in OS X v10.4 and later.

  • Performs layout of the inner views.

    Declaration

    - (void)layoutDocumentView

    Discussion

    The PDFView actually contains several subviews, such as the document view (where the PDF is actually drawn) and a “matte view” (which may appear as a gray area around the PDF content, depending on the scaling). Changes to the PDF content may require changes to these inner views, so you must call this method explicitly if you use PDF Kit utility classes to add or remove a page, rotate a page, or perform other operations affecting visible layout.

    This method is called automatically from PDFView methods that affect the visible layout (such as setDocument:, setDisplayBox: or zoomIn:).

    Availability

    Available in OS X v10.4 and later.

  • Determines whether the view can accept new PDF documents dragged into it by the user.

    Declaration

    - (BOOL)allowsDragging

    Availability

    Available in OS X v10.4 and later.

  • Specifies whether the view can accept drags.

    Declaration

    - (void)setAllowsDragging:(BOOL)allow

    Discussion

    If set to YEStrue, the user can drag a new PDF document into the view. The new document is then displayed in the view, and the old document is released.

    Availability

    Available in OS X v10.4 and later.

  • Returns an array of PDFPage objects that represent the currently visible pages.

    Declaration

    - (NSArray *)visiblePages

    Availability

    Available in OS X v10.5 and later.

  • Tells the PDF view that an annotation on the specified page has changed.

    Declaration

    - (void)annotationsChangedOnPage:(PDFPage *)page

    Discussion

    When the PDFView object receives this message, it rescans for tool tips and pop-ups and informs the PDFThumbailView objects so the thumbnail images can be redrawn.

    Availability

    Available in OS X v10.5 and later.

  • Delegate method for overriding changes to scale factor.

    Declaration

    - (float)PDFViewWillChangeScaleFactor:(PDFView *)sender toScale:(float)scale

    Discussion

    By default, the scale factor is restricted to a range between 0.1 and 10.0 inclusive.

    Availability

    Available in OS X v10.4 and later.

  • Delegate method for handling clicks on URL links in a view.

    Declaration

    - (void)PDFViewWillClickOnLink:(PDFView *)sender withURL:(NSURL *)url

    Discussion

    By default, this method calls [[NSWorkspace sharedWorkspace] openURL:url].

    Availability

    Available in OS X v10.5 and later.

  • Delegate method that performs a find operation.

    Declaration

    - (void)PDFViewPerformFind:(PDFView *)sender

    Discussion

    Some PDFAction objects request a PDF viewer application to perform a find operation. A delegate responding to this method is called when users click an annotation with such an action.

    Availability

    Available in OS X v10.5 and later.

  • Delegate method that performs a go-to operation.

    Declaration

    - (void)PDFViewPerformGoToPage:(PDFView *)sender

    Discussion

    Some PDFAction objects request a PDF viewer application to display a panel that allows users to enter a page number to go to. A delegate responding to this method is called when users click an annotation with such an action.

    Availability

    Available in OS X v10.5 and later.

  • Delegate method that prints the current document.

    Declaration

    - (void)PDFViewPerformPrint:(PDFView *)sender

    Discussion

    Some PDFAction objects request a PDF viewer application to print the current document. A delegate responding to this method is called when users click an annotation with such an action.

    Availability

    Available in OS X v10.5 and later.

  • Delegate method that opens a specified page.

    Declaration

    - (void)PDFViewOpenPDF:(PDFView *)sender forRemoteGoToAction:(PDFActionRemoteGoTo *)action

    Discussion

    A delegate responding to this method is called to handle clicks in an annotation that contains a PDFActionRemoteGoTo action. Such an action contains a URL, a page index, and a point. The delegate should open the PDF document specified by the URL and go to the specified page and point. An easy way to do this is to create a PDFDocument object with the specified URL and then create a PDFDestination object with the specified page and point. Then, you can call goToDestination:.

    The default implementation of this method beeps.

    Availability

    Available in OS X v10.5 and later.

  • Delegate method that overrides the job title used when the PDFView is printed.

    Declaration

    - (NSString *)PDFViewPrintJobTitle:(PDFView *)sender

    Discussion

    By default, this method uses the string, if any, associated with the “Title” key in the view’s PDFDocument attribute dictionary. If there is no such string, this method uses the last path component if the document is URL-based.

    Availability

    Available in OS X v10.5 and later.

  • Posted when the page history changes.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted when a new document is associated with the view.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted when a new page becomes the current page.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted when the scale factor changes.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted when the user clicks on an annotation.

    The notification object is the PDFView object itself.

    Use the @”PDFAnnotationHit” key to obtain userinfo of type PDFAnnotation *.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted when the user attempts to copy to the pasteboard without the appropriate permissions.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted when the user attempts to print without the appropriate permissions.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

  • Posted before the user clicks an annotation.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.5 and later.

  • Posted when the current selection has changed.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.5 and later.

  • Posted when the display mode has changed.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.5 and later.

  • Posted when the display box has changed.

    The notification object is the PDFView object itself.

    Import Statement

    Availability

    Available in OS X v10.5 and later.