Class

PDFView

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

Overview

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.

Symbols

Associating a Document with a View

var document: PDFDocument?

Returns the document associated with a PDFView object.

Navigating Within a Document

func canGoBack()

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

func canGoForward()

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

func canGoToFirstPage()

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

func canGoToLastPage()

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

func canGoToNextPage()

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

func canGoToPreviousPage()

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

var currentPage: PDFPage?

Returns the current page.

var currentDestination: PDFDestination?

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

func goBack(Any?)

Navigates back one step in the page history.

func goForward(Any?)

Navigates forward one step in the page history.

func goToFirstPage(Any?)

Navigates to the first page of the document.

func goToLastPage(Any?)

Navigates to the last page of the document.

func goToNextPage(Any?)

Navigates to the next page of the document.

func goToPreviousPage(Any?)

Navigates to the previous page of the document.

func go(to: PDFPage)

Scrolls to the specified page.

func go(to: PDFDestination)

Navigates to the specified destination.

func go(to: PDFSelection)

Scrolls to the first character of the specified selection.

func go(to: NSRect, on: PDFPage)

Navigates to the specified rectangle on the specified page.

Working with Display Modes and Characteristics

var displayMode: PDFDisplayMode

Returns the current display mode.

var displaysPageBreaks: Bool

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

var displayBox: PDFDisplayBox

Returns the current style of display box.

var displaysAsBook: Bool

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).

var shouldAntiAlias: Bool

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

Deprecated
var greekingThreshold: CGFloat

Returns the current greeking threshold for the view.

Deprecated
func takeBackgroundColorFrom(Any)

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

Deprecated
var backgroundColor: NSColor

Returns the view’s background color.

Setting the Delegate

var delegate: PDFViewDelegate?

Returns the view’s delegate.

Scaling the View

var scaleFactor: CGFloat

Returns the current scale factor for the view.

func zoomIn(Any?)

Zooms in by increasing the scaling factor.

func canZoomIn()

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

func zoomOut(Any?)

Zooms out by decreasing the scaling factor.

func canZoomOut()

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

var autoScales: Bool

Returns a Boolean value indicating whether autoscaling is set.

Working with Mouse Position and Events

func areaOfInterest(forMouse: NSEvent)

Returns the type of area the mouse cursor is over.

func setCursorFor(PDFAreaOfInterest)

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

func perform(PDFAction)

Performs the specified action.

Handling Selections

var currentSelection: PDFSelection?

Returns the current selection.

func selectAll(Any?)

Selects all text in the document.

func clearSelection()

Clears the selection.

func copy(Any?)

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

func scrollSelectionToVisible(Any?)

Scrolls the view until the selection is visible.

func setCurrentSelection(PDFSelection?, animate: Bool)

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

var highlightedSelections: [PDFSelection]?

Returns the array of selections that are highlighted using setHighlightedSelections.

Setting the Password

func takePasswordFrom(Any)

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

Deprecated

Rendering the View and Printing

func draw(PDFPage)

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

Deprecated
func drawPagePost(PDFPage)

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

Deprecated
func print(with: NSPrintInfo, autoRotate: Bool)

Prints the document with the specified printer information.

func print(with: NSPrintInfo, autoRotate: Bool, pageScaling: PDFPrintScalingMode)

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

Conversion Methods for Subclasses

func page(for: NSPoint, nearest: Bool)

Returns the page containing a point specified in view coordinates.

func convert(NSPoint, to: PDFPage)

Converts a point from view space to page space.

func convert(NSRect, to: PDFPage)

Converts a rectangle from view space to page space.

func convert(NSPoint, from: PDFPage)

Converts a point from page space to view space.

func convert(NSRect, from: PDFPage)

Converts a rectangle from page space to view space.

Miscellaneous Methods

var documentView: NSView?

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

func rowSize(for: PDFPage)

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

func layoutDocumentView()

Performs layout of the inner views.

var allowsDragging: Bool

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

func visiblePages()

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

func annotationsChanged(on: PDFPage)

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

Constants

PDFDisplayMode

PDF views use the following display mode constants.

PDFAreaOfInterest

The following constants apply to mouse position over PDF view areas. These constants are components of a bit field and may be combined arbitrarily.

Notifications

A PDFView object posts the following notifications:

static let PDFViewChangedHistory: NSNotification.Name

Posted when the page history changes.

static let PDFViewDocumentChanged: NSNotification.Name

Posted when a new document is associated with the view.

static let PDFViewPageChanged: NSNotification.Name

Posted when a new page becomes the current page.

static let PDFViewScaleChanged: NSNotification.Name

Posted when the scale factor changes.

static let PDFViewAnnotationHit: NSNotification.Name

Posted when the user clicks on an annotation.

static let PDFViewCopyPermission: NSNotification.Name

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

static let PDFViewPrintPermission: NSNotification.Name

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

static let PDFViewAnnotationWillHit: NSNotification.Name

Posted before the user clicks an annotation.

static let PDFViewSelectionChanged: NSNotification.Name

Posted when the current selection has changed.

static let PDFViewDisplayModeChanged: NSNotification.Name

Posted when the display mode has changed.

static let PDFViewDisplayBoxChanged: NSNotification.Name

Posted when the display box has changed.