---
title: "setURL(_:for:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uigraphicspdfrenderercontext/seturl(_:for:)"
---

# setURL(_:for:)

Creates a link to an external resource defined by a URL

## Declaration

```swift
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

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 userSpaceToDeviceSpaceTransform property on CGContext to map between the two. To create internal links within the current PDF document, use addDestination(withName:at:) and setDestinationWithName(_:for:).

## See Also

### Managing destinations

- [addDestination(withName:at:)](uikit/uigraphicspdfrenderercontext/adddestination(withname:at:).md)
- [setDestinationWithName(_:for:)](uikit/uigraphicspdfrenderercontext/setdestinationwithname(_:for:).md)
