---
title: "Attach files to PDFs on iOS"
canonical_url: "https://www.nutrient.io/guides/ios/editor/attach-a-file/"
md_url: "https://www.nutrient.io/guides/ios/editor/attach-a-file.md"
last_updated: "2026-05-25T06:31:34.519Z"
description: "Learn how to embed files in PDFs on iOS with FileAnnotation and EmbeddedFile effectively."
---

# How to attach files to PDFs on iOS

Nutrient iOS SDK has the ability to embed files using [`FileAnnotation`](https://www.nutrient.io/api/ios/documentation/pspdfkit/fileannotation/embeddedfile) and [`EmbeddedFile`](https://www.nutrient.io/api/ios/documentation/pspdfkit/embeddedfile). Take a look at the [file annotations with embedded files](https://www.nutrient.io/guides/ios/annotations/programmatically-creating-annotations.md#file-annotations-with-embedded-files) section of the programmatically creating annotations guide, along with `AddFileAnnotationProgrammaticallyExample` inside the Catalog app, both of which show how to programmatically create file annotations with embedded files.

See also: [How to embed files using file annotations](https://www.nutrient.io/blog/how-to-embed-files-using-file-annotations/) on our blog.

## Programmatically create a file annotation with an embedded file

Embedded files can be attached to a [`FileAnnotation`](https://www.nutrient.io/api/ios/documentation/pspdfkit/fileannotation/embeddedfile) object. You can create a file annotation with an embedded file using the URL of any file. Here’s how this looks in code:

### SWIFT

```swift

// Create `Document`.
let document = Document(url: documentURL)

// Create the URL of the appearance stream that uses a PDF file.
let samplesURL = Bundle.main.resourceURL!.appendingPathComponent("Samples")
let embeddedFileURL = samplesURL.appendingPathComponent("Monthly Budget.xlsx")

// Create a new file annotation and set its properties.
let fileAnnotation = FileAnnotation()
fileAnnotation.pageIndex = 0
fileAnnotation.iconName =.graph
fileAnnotation.color =.blue
fileAnnotation.boundingBox = CGRect(x: 500, y: 250, width: 32, height: 32)

// Create an embedded file and add it to the file annotation.
let embeddedFile = EmbeddedFile(fileURL: embeddedFileURL, fileDescription: "Monthly Budget")
fileAnnotation.embeddedFile = embeddedFile

// Add the newly created annotation to the document.
document.add(annotations: [fileAnnotation])

```

### OBJECTIVE-C

```objc

// Create `PSPDFDocument`.
PSPDFDocument *document = [[PSPDFDocument alloc] initWithURL:documentURL];

// Create the URL of the appearance stream that uses a PDF file.
NSURL *samplesURL = [NSBundle.mainBundle.resourceURL URLByAppendingPathComponent:@"Samples"];
NSURL *embeddedFileURL = [samplesURL URLByAppendingPathComponent:@"Monthly Budget.xlsx"];

// Create a new file annotation and set its properties.
PSPDFFileAnnotation *fileAnnotation = [[PSPDFFileAnnotation alloc] init];
fileAnnotation.pageIndex = 0;
fileAnnotation.iconName = PSPDFFileIconNameGraph;
fileAnnotation.color = UIColor.blueColor;
fileAnnotation.boundingBox = CGRectMake(500.0, 250.0, 32.0, 32.0);

// Create an embedded file and add it to the file annotation.
PSPDFEmbeddedFile *embeddedFile = [[PSPDFEmbeddedFile alloc] initWithFileURL:embeddedFileURL fileDescription:@"Monthly Budget"];
fileAnnotation.embeddedFile = embeddedFile;
[document addAnnotations:@[fileAnnotation] options:nil];

```

To learn more about how to programmatically create file annotations with embedded files, check out `AddFileAnnotationProgrammaticallyExample` inside the [Catalog app](https://www.nutrient.io/guides/ios/getting-started/example-projects.md).
---

## Related pages

- [Add and insert images into PDFs on iOS](/guides/ios/editor/add-image.md)
- [Add pages to PDF files on iOS](/guides/ios/editor/add-page.md)
- [Customizing PDF editing permissions on iOS](/guides/ios/editor/document-permissions.md)
- [iOS PDF editor API usage](/guides/ios/features/document-editor.md)
- [Edit text in PDFs on iOS](/guides/ios/editor/edit-text.md)
- [Merge multiple PDF files on iOS](/guides/ios/editor/merge-or-combine.md)
- [PDF editor library for iOS](/guides/ios/features/document-processing.md)
- [Split PDFs on iOS](/guides/ios/editor/split.md)
- [Adding watermarks to PDFs on iOS](/guides/ios/editor/watermark.md)

