---
title: "Instantiate a download from a remote URL"
canonical_url: "https://www.nutrient.io/guides/ios/miscellaneous/document-downloads/"
md_url: "https://www.nutrient.io/guides/ios/miscellaneous/document-downloads.md"
last_updated: "2026-06-09T10:25:14.472Z"
description: "Learn how to use Nutrient to instantiate PDF documents from remote URLs, enhance performance, and manage caching effectively."
---

Nutrient usually works best with PDF documents on the local file system of your device. There are several reasons for using local file system documents (these include performance, cache control, and battery impact).

However, if you have a PDF document that isn’t on the local file system, you can also instantiate a [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document) with a remote URL via [`Document(url:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document):

```swift

let document = Document(url: URL(string: "https://github.com/PSPDFKit/pspdfkit-ios-catalog/raw/master/Samples/Magazine.pdf")!)
let controller = PDFViewController(document: document)

```

This will download the remote document and cache it. If you’re interested in how this works exactly, check out our [blog post about it](https://www.nutrient.io/blog/downloading-large-files-with-urlsession/). You can also disable caching by doing the following:

```swift

// By default, downloads use this custom large cache to ensure files are being updated correctly.
// Set the cache to `nil` to disable this caching.
// /blog/downloading-large-files-with-urlsession/
URLDataProvider.cache = nil

// Ensure the temporary file does not exist.
try? FileManager.default.removeItem(at: URLDataProvider.defaultTargetURL(for: url)!)

```

Files downloaded from a remote URL using this method are read-only by default, and annotations cannot be saved, as the source file could change at any time.

Refer to [`RemoteDocumentURLExample.swift`] in the [Nutrient Catalog](https://www.nutrient.io/guides/ios/getting-started/example-projects.md#nutrient-catalog) for a complete example.

## Downloading documents using URLSession

If you want to annotate a remote document or make changes to it, you can use [`URLSession`](https://developer.apple.com/documentation/foundation/urlsession) to download the PDF. Then move it to a permanent location and display it using [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller).

Create a [`URLSession`](https://developer.apple.com/documentation/foundation/urlsession) object with the required configurations. Then, use the session to create a download task ([`URLSessionDownloadTask`](http://developer.apple.com/documentation/foundation/urlsessiondownloadtask)) with the remote URL of the PDF document. Before resuming the task, make sure you’ve set the session object’s delegate:

### SWIFT

```swift

let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: OperationQueue.main)
let task = session.downloadTask(with: URL(string: "https://github.com/PSPDFKit/pspdfkit-ios-catalog/raw/master/Samples/Magazine.pdf")!)
task.resume()

```

### OBJECTIVE-C

```objc

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionDownloadTask *task = [session downloadTaskWithURL:[NSURL URLWithString:@"https://github.com/PSPDFKit/pspdfkit-ios-catalog/raw/master/Samples/Magazine.pdf"]];
[task resume];

```

Once the file is downloaded, the [`urlSession(_:downloadTask:didFinishDownloadingTo:)`](https://developer.apple.com/documentation/foundation/urlsessiondownloaddelegate/1411575-urlsession) delegate method is called where the `location` object is a temporary file URL. Hence it should be moved to a permanent location before opening it with [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller):

### SWIFT

```swift

func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
    // The desired saving location of the file is `destinationFileURL`, which `PDFViewController` will later use for loading.
    try! FileManager.default.moveItem(at: location, to: destinationFileURL)
}

```

### OBJECTIVE-C

```objc

- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
    NSError *error;

    // The desired saving location of the file is `destinationFileURL`, which `PDFViewController` will later use for loading.
    [[NSFileManager defaultManager] moveItemAtURL:location toURL:destinationFileURL error:&error];
    if (error) {
        NSLog(@"%@", error.localizedDescription);
    }
}

```

Refer to [`DocumentProgressExample.swift`] in the [Nutrient Catalog](https://www.nutrient.io/guides/ios/getting-started/example-projects.md#nutrient-catalog) for a complete example.
---

## Related pages

- [Open a PDF from a custom data provider on iOS](/guides/ios/features/data-providers.md)
- [File coordination on iOS](/guides/ios/features/file-coordination.md)
- [Open a PDF from in-memory data on iOS](/guides/ios/open-a-document/from-in-memory-data.md)
- [Open a PDF from Document Engine on iOS](/guides/ios/open-a-document/from-document-engine.md)
- [Open a local file on iOS](/guides/ios/open-a-document/from-local-storage.md)
- [Open a PDF on iOS](/guides/ios/open-a-document.md)
- [Open password-protected PDFs on iOS](/guides/ios/open-a-document/password-protected-pdfs.md)
- [Troubleshoot opening a document](/guides/ios/open-a-document/troubleshooting.md)


---

## Related pages

- [Options to disable or enable PDF editing on iOS](/guides/ios/features/controlling-pdf-editing.md)
- [Adding Custom Views To A Page](/guides/ios/customizing-pdf-pages/adding-custom-views-to-a-page.md)
- [Document Features](/guides/ios/features/document-features.md)
- [Adding Auxiliary Or Decorative Views](/guides/ios/customizing-pdf-pages/adding-auxiliary-or-decorative-views.md)
- [SwiftUI PDF library](/guides/ios/getting-started/swiftui.md)
- [Configure document sharing options on iOS](/guides/ios/miscellaneous/document-sharing.md)

