Mac Developer Library

Developer

Quartz Framework Reference PDFPage Class Reference

Options
Deployment Target:

On This Page
Language:

PDFPage

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

Inheritance


Conforms To


Import Statement


import Quartz @import Quartz;

Availability


Available in OS X v10.4 and later.
  • Initializer for subclasses of PDFPage.

    Use [PDFPage init] or initWithImage: instead.

    Declaration

    Objective-C

    - (id)initWithDocument:(PDFDocument *)document

    Discussion

    Subclasses of PDFPage must handle several methods that are transparently handled when using the PDFPage class directly, including boundsForBox and drawInRect:withBox:.

    Import Statement

    Availability

    Available in OS X v10.4 and later.

    Not available to 64-bit applications.

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

    Declaration

    Swift

    init!(image image: NSImage!)

    Objective-C

    - (id)initWithImage:(NSImage *)image

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.5 and later.

  • Returns the PDFDocument object with which the page is associated.

    Declaration

    Swift

    func document() -> PDFDocument!

    Objective-C

    - (PDFDocument *)document

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

  • Returns the label for the page.

    Declaration

    Swift

    func label() -> String!

    Objective-C

    - (NSString *)label

    Discussion

    Typically, the label is “1” for the first page, “2” for the second page, and so on, but nonnumerical labels are also possible (such as “xxi”, “4-1” and so on).

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

    See Also

    – document

  • Returns the bounds for the specified PDF display box.

    Declaration

    Swift

    func boundsForBox(_ box: PDFDisplayBox) -> NSRect

    Objective-C

    - (NSRect)boundsForBox:(PDFDisplayBox)box

    Discussion

    The PDFDisplayBox enumeration defines the various box types (see Constants for additional information about box types).

    Note that only the media box is required for a PDF. If you request the bounds for the crop box, but the PDF does not include a crop box, the bounds for the media box are returned instead. If you request the bounds for other box types, and the PDF does not includes these types, the bounds for the crop box are returned instead.

    The coordinates for the box are in page space, so you might need to transform the points if the page has a rotation on it. Also, note that the bounds boundsForBox returns are intersected with the page’s media box.

    boundsForBox throws a range exception if box is not in range.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

  • Sets the bounds for the specified box.

    Declaration

    Swift

    func setBounds(_ bounds: NSRect, forBox box: PDFDisplayBox)

    Objective-C

    - (void)setBounds:(NSRect)bounds forBox:(PDFDisplayBox)box

    Discussion

    If the box does not exist, this method creates it for you.

    To remove a box, pass NSZeroRect for the bounds (note that you cannot remove the media box). If the box bounds are not in range, this method throws a range exception.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

  • Returns the page rotation angle in degrees.

    Declaration

    Swift

    func rotation() -> Int

    Objective-C

    - (NSInteger)rotation

    Discussion

    The rotation is a positive multiple of 90: 0, 90, 180, or 270. The rotation of pages with negative rotation is converted to a corresponding positive rotation.

    If you are subclassing PDFView and displaying pages yourself, don’t assume a rotation of 0. Pages with an inherent rotation display rotated when opened unless you set their rotation to zero. Regardless of the inherent rotation angle, it is up to the author of a page whether zero rotation corresponds to upright text when displayed on a monitor.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

  • Sets the rotation angle for the page in degrees.

    Declaration

    Swift

    func setRotation(_ angle: Int)

    Objective-C

    - (void)setRotation:(NSInteger)angle

    Discussion

    The rotation must be a positive or negative multiple of 90 (negative angles are converted to their positive equivalents; for example, -90 is changed to 270); otherwise this method throws an exception.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

    See Also

    – rotation

  • Draws the page within the specified box.

    Declaration

    Swift

    func drawWithBox(_ box: PDFDisplayBox)

    Objective-C

    - (void)drawWithBox:(PDFDisplayBox)box

    Discussion

    This method takes into account the page rotation and draws clipped to the specified box. If the page is set to display annotations, this method also draws them. This method does not clear the background. To clear the background before drawing, use NSRectFill with NSColor set (typically) to white.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

  • Transforms the current context, given the specified box.

    Declaration

    Swift

    func transformContextForBox(_ box: PDFDisplayBox)

    Objective-C

    - (void)transformContextForBox:(PDFDisplayBox)box

    Discussion

    When transforming the current context, this method takes into account the rotation of the page, as well as the origin of the box with respect to the page’s base coordinate system. This is a convenient method to call within the PDFView drawPage: method or from within a draw method of a PDFAnnotation subclass.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    func numberOfCharacters() -> Int

    Objective-C

    - (NSUInteger)numberOfCharacters

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

    See Also

    – string

  • Returns an NSString object representing the text on the page.

    Declaration

    Swift

    func string() -> String!

    Objective-C

    - (NSString *)string

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

  • Returns an NSAttributedString object representing the text on the page.

    Declaration

    Swift

    func attributedString() -> NSAttributedString!

    Objective-C

    - (NSAttributedString *)attributedString

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func characterBoundsAtIndex(_ index: Int) -> NSRect

    Objective-C

    - (NSRect)characterBoundsAtIndex:(NSInteger)index

    Discussion

    In the unlikely event that there is more than one character at the specified index point, only the bounds of the first character is returned.

    Page space is a 72 dpi coordinate system with the origin at the lower-left corner of the current page. Note that the bounds returned are not guaranteed to have integer coordinates.

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func characterIndexAtPoint(_ point: NSPoint) -> Int

    Objective-C

    - (NSInteger)characterIndexAtPoint:(NSPoint)point

    Discussion

    If there is no character at the specified point, the method returns -1.

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

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func dataRepresentation() -> NSData!

    Objective-C

    - (NSData *)dataRepresentation

    Import Statement

    import Quartz

    Availability

    Available in OS X v10.4 and later.