<!--
{
  "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: PDFDocument)`](/documentation/PDFKit/PDFSelection/init(document:))

Returns an empty `PDFSelection` object.

### Getting Information About a Selection

[`var pages: [PDFPage]`](/documentation/PDFKit/PDFSelection/pages)

Returns the array of pages contained in the selection.

[`var string: String?`](/documentation/PDFKit/PDFSelection/string)

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

[`var attributedString: NSAttributedString?`](/documentation/PDFKit/PDFSelection/attributedString)

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

[`func bounds(for: PDFPage) -> CGRect`](/documentation/PDFKit/PDFSelection/bounds(for:))

Returns the bounds of the selection on the specified page.

[`func selectionsByLine() -> [PDFSelection]`](/documentation/PDFKit/PDFSelection/selectionsByLine())

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

[`var color: UIColor?`](/documentation/PDFKit/PDFSelection/color)

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

### Modifying a Selection

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

Adds the specified selection to the receiving selection.

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

Adds the specified array of selections to the receiving selection.

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

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

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

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

### Managing Selection Drawing

[`func draw(for: PDFPage, active: Bool)`](/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.

[`func draw(for: PDFPage, with: PDFDisplayBox, active: Bool)`](/documentation/PDFKit/PDFSelection/draw(for:with:active:))

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

[`var color: UIColor?`](/documentation/PDFKit/PDFSelection/color)

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

### Instance Methods

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

[`func numberOfTextRanges(on: PDFPage) -> Int`](/documentation/PDFKit/PDFSelection/numberOfTextRanges(on:))

[`func range(at: Int, on: PDFPage) -> NSRange`](/documentation/PDFKit/PDFSelection/range(at:on:))

## Relationships

### Conforms To

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)