<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIGraphicsPDFRendererContext/setURL(_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIGraphicsPDFRendererContext(im)setURL:forRect:"
  },
  "title" : "setURL(_:for:)"
}
-->

# setURL(_:for:)

Creates a link to an external resource defined by a URL

```
func setURL(_ url: URL, for rect: CGRect)
```

## Parameters

`url`

The external URL that the user is directed to on clicking the link.

`rect`

The region of the current page that becomes the active link area, specified in points in the PDF coordinate space.

## Discussion

Use this method to create links to external resources in the current page of a PDF. The URL is interpreted by the PDF viewer.

> Note:
> Specify the `rect` value in the PDF coordinate space, not the Core Graphics context coordinate space. This means that the origin is in the bottom-left rather than the top-left, and the y-axis increases in an upwards direction. Use the <doc://com.apple.documentation/documentation/CoreGraphics/CGContext/userSpaceToDeviceSpaceTransform> property on <doc://com.apple.documentation/documentation/CoreGraphics/CGContext> to map between the two.

To create internal links within the current PDF document, use [`addDestination(withName:at:)`](/documentation/UIKit/UIGraphicsPDFRendererContext/addDestination(withName:at:)) and [`setDestinationWithName(_:for:)`](/documentation/UIKit/UIGraphicsPDFRendererContext/setDestinationWithName(_:for:)).

---

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)