PDFPage Class Reference
| Inherits from | |
| Conforms to | |
| Framework | Library/Frameworks/Quartz.framework/Frameworks/PDFKit.framework |
| Availability | Available in OS X v10.4 and later. |
| Declared in | PDFPage.h |
Overview
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.
Tasks
Initializing a Page
Getting Information About a Page
Working with Annotations
-
– annotations -
– displaysAnnotations -
– setDisplaysAnnotations: -
– addAnnotation: -
– removeAnnotation: -
– annotationAtPoint:
Rendering Pages
Working with Textual Content
Working with Selections
-
– selectionForRect: -
– selectionForWordAtPoint: -
– selectionForLineAtPoint: -
– selectionFromPoint:toPoint: -
– selectionForRange:
Miscellaneous
Instance Methods
addAnnotation:
Adds the specified annotation object to the page.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hannotationAtPoint:
Returns the annotation, if there is one, at the specified point.
Discussion
Use this method for hit-testing based on the current cursor position. If more than one annotation shares the specified point, the frontmost (or topmost) one is returned (the annotations are searched in reverse order of their appearance in the PDF data file). Returns NULL if there is no annotation at point.
Specify the point 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
Declared In
PDFPage.hannotations
Returns an array containing the page’s annotations.
Discussion
The elements of the array will most likely be typed to subclasses of the PDFAnnotation class.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hattributedString
Returns an NSAttributedString object representing the text on the page.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hboundsForBox:
Returns the bounds for the specified PDF display 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.
Availability
- Available in OS X v10.4 and later.
See Also
-
– setBounds:forBox:
Declared In
PDFPage.hcharacterBoundsAtIndex:
Returns the bounds, in page space, of the character at the specified 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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hcharacterIndexAtPoint:
Returns the character index value for the specified point in page space.
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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hdataRepresentation
Returns the PDF data (that is, a PDF document) representing this page. This method does not preserve external page links.
Availability
- Available in OS X v10.4 and later.
Declared In
PDFPage.hdisplaysAnnotations
Returns a Boolean value indicating whether annotations are displayed for the page.
Discussion
If YES, the page will draw annotations when a drawing method is called.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hdocument
Returns the PDFDocument object with which the page is associated.
Availability
- Available in OS X v10.4 and later.
Declared In
PDFPage.hdrawWithBox:
Draws the page within the specified 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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hinitWithDocument:
Initializer for subclasses of PDFPage. (Deprecated. Use [PDFPage init] or initWithImage: instead.)
Discussion
Subclasses of PDFPage must handle several methods that are transparently handled when using the PDFPage class directly, including boundsForBox and drawInRect:withBox:.
Availability
- Available in OS X v10.4 and later.
Declared In
PDFPage.hinitWithImage:
Creates a new PDFPage object and initializes it with the specified NSImage object.
Availability
- Available in OS X v10.5 and later.
Declared In
PDFPage.hlabel
Returns the label for the page.
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).
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hnumberOfCharacters
Returns the number of characters on the page, including whitespace characters.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hremoveAnnotation:
Removes the specified annotation from the page.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hrotation
Returns the page rotation angle in degrees.
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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hselectionForLineAtPoint:
Returns the whole line of text that includes the specified point.
Discussion
Returns NULL if no line of text contains point.
Use this method to respond to a triple-click.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hselectionForRange:
Returns the text contained within the specified range.
Discussion
This method raises an exception if the range length is 0 or if either end of the range is outside the range of characters on the page.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hselectionForRect:
Returns the text enclosed within the specified rectangle, expressed in page (user) coordinates.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hselectionForWordAtPoint:
Returns the whole word that includes the specified point.
Discussion
Returns NULL if no word contains point.
Use this method to respond to a double-click.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hselectionFromPoint:toPoint:
Returns the text between the two specified points in page space.
Discussion
Either point may be the one closer to the start of the page. In determining the selection, the points are sorted first top to bottom and then left to right.
Page space is a 72 dpi coordinate system with the origin at the lower-left corner of the current page.
To visualize the selection, picture the rectangle defined by startPoint and endPoint. The selection begins at the first character fully within the defined rectangle and closest to its upper-left corner. The selection ends at the last character fully within the defined rectangle and closest to its lower-right corner.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hsetBounds:forBox:
Sets the bounds for the specified 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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hsetDisplaysAnnotations:
Specifies whether or not to display annotations for the page.
Discussion
If display is YES, the page will draw annotations when a drawing method is called.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hsetRotation:
Sets the rotation angle for the page in degrees.
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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.hstring
Returns an NSString object representing the text on the page.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
PDFPage.htransformContextForBox:
Transforms the current context, given the specified 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.
Availability
- Available in OS X v10.5 and later.
See Also
-
– drawWithBox:
Declared In
PDFPage.hConstants
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.
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-12-11)