PDFPage, a subclass of NSObject, defines methods used to render PDF pages and work with annotations, text, and selections.


PDFPage objects are flexible and powerful. With them you can render PDF content onscreen or to a printer, add annotations, count characters, define selections, and get the textual content of a page as an NSString object.

Your application instantiates a PDFPage object by asking for one from a PDFDocument object.

For simple display and navigation of PDF documents within your application, you don’t need to use PDFPage. You need only use PDFView.


Initializing a Page

init?(image: NSImage)

Creates a new PDFPage object and initializes it with the specified NSImage object.

Getting Information About a Page

var document: PDFDocument?

Returns the PDFDocument object with which the page is associated.

var label: String?

Returns the label for the page.

func bounds(for: PDFDisplayBox)

Returns the bounds for the specified PDF display box.

func setBounds(NSRect, for: PDFDisplayBox)

Sets the bounds for the specified box.

var rotation: Int

Sets the rotation angle for the page in degrees.

Working with Annotations

var annotations: [PDFAnnotation]

Returns an array containing the page’s annotations.

var displaysAnnotations: Bool

Returns a Boolean value indicating whether annotations are displayed for the page.

func addAnnotation(PDFAnnotation)

Adds the specified annotation object to the page.

func removeAnnotation(PDFAnnotation)

Removes the specified annotation from the page.

func annotation(at: NSPoint)

Returns the annotation, if there is one, at the specified point.

Rendering Pages

func draw(with: PDFDisplayBox)

Draws the page within the specified box.

func transformContext(for: PDFDisplayBox)

Transforms the current context, given the specified box.


Working with Textual Content

var numberOfCharacters: Int

Returns the number of characters on the page, including whitespace characters.

var string: String?

Returns an NSString object representing the text on the page.

var attributedString: NSAttributedString?

Returns an NSAttributedString object representing the text on the page.

func characterBounds(at: Int)

Returns the bounds, in page space, of the character at the specified index.

func characterIndex(at: NSPoint)

Returns the character index value for the specified point in page space.

Working with Selections

func selection(for: NSRect)

Returns the text enclosed within the specified rectangle, expressed in page (user) coordinates.

func selectionForWord(at: NSPoint)

Returns the whole word that includes the specified point.

func selectionForLine(at: NSPoint)

Returns the whole line of text that includes the specified point.

func selection(from: NSPoint, to: NSPoint)

Returns the text between the two specified points in page space.

func selection(for: NSRange)

Returns the text contained within the specified range.


var dataRepresentation: Data

Returns the PDF data (that is, a PDF document) representing this page. This method does not preserve external page links.



The following box types may be used with PDFPage drawing and bounds-setting methods. See the Adobe PDF Specification for more information on box types, units, and coordinate systems.

Instance Properties


Inherits From