<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PDFKit",
  "identifier" : "/documentation/PDFKit/PDFSelection",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "PDFKit"
    ],
    "preciseIdentifier" : "c:objc(cs)PDFSelection"
  },
  "title" : "PDFSelection"
}
-->

# PDFSelection

A `PDFSelection` object identifies a contiguous or noncontiguous selection of text in a PDF document.

```
class PDFSelection
```

## Topics

### Initializing a Selection

[`init(document:)`](/documentation/PDFKit/PDFSelection/init(document:))

Returns an empty `PDFSelection` object.

### Getting Information About a Selection

[`pages`](/documentation/PDFKit/PDFSelection/pages)

Returns the array of pages contained in the selection.

[`string`](/documentation/PDFKit/PDFSelection/string)

Returns an `NSString` object representing the text contained in the selection (may contain linefeed characters).

[`attributedString`](/documentation/PDFKit/PDFSelection/attributedString)

Returns an `NSAttributedString` object representing the text contained in the selection (may contain linefeed characters).

[`bounds(for:)`](/documentation/PDFKit/PDFSelection/bounds(for:))

Returns the bounds of the selection on the specified page.

[`selectionsByLine()`](/documentation/PDFKit/PDFSelection/selectionsByLine())

Returns an array of selections, one for each line of text covered by the receiver.

[`color`](/documentation/PDFKit/PDFSelection/color)

Sets the color used for the drawing of a selection in both active and inactive states.

### Modifying a Selection

[`add(_:)`](/documentation/PDFKit/PDFSelection/add(_:)-8c2r)

Adds the specified selection to the receiving selection.

[`add(_:)`](/documentation/PDFKit/PDFSelection/add(_:)-3fyld)

Adds the specified array of selections to the receiving selection.

[`extend(atEnd:)`](/documentation/PDFKit/PDFSelection/extend(atEnd:))

Extends the selection from its end toward the end of the document.

[`extend(atStart:)`](/documentation/PDFKit/PDFSelection/extend(atStart:))

Extends the selection from its start toward the beginning of the document.

### Managing Selection Drawing

[`draw(for:active:)`](/documentation/PDFKit/PDFSelection/draw(for:active:))

Calls [`draw(for:with:active:)`](/documentation/PDFKit/PDFSelection/draw(for:with:active:)) with a default value for box parameter.

[`draw(for:with:active:)`](/documentation/PDFKit/PDFSelection/draw(for:with:active:))

Draws the selection relative to the origin of the specified box in page space.

[`color`](/documentation/PDFKit/PDFSelection/color)

Sets the color used for the drawing of a selection in both active and inactive states.

### Instance Methods

[`extendForLineBoundaries()`](/documentation/PDFKit/PDFSelection/extendForLineBoundaries())

[`numberOfTextRanges(on:)`](/documentation/PDFKit/PDFSelection/numberOfTextRanges(on:))

[`range(at:on:)`](/documentation/PDFKit/PDFSelection/range(at:on:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)