---
title: "Embed files in PDF on iOS"
canonical_url: "https://www.nutrient.io/guides/ios/annotations/create-edit-and-remove/attach-a-file/"
md_url: "https://www.nutrient.io/guides/ios/annotations/create-edit-and-remove/attach-a-file.md"
last_updated: "2026-06-18T03:06:48.919Z"
description: "Learn to embed files in PDF annotations on iOS using FileAnnotation and EmbeddedFile."
---

# How to embed files in PDF annotations 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

- [Define annotation behavior with flags on iOS](/guides/ios/annotations/annotation-flags.md)
- [Annotations object model on iOS](/guides/ios/annotations/the-annotation-object-model.md)
- [Defining annotation blend modes on iOS](/guides/ios/annotations/annotation-blend-modes.md)
- [Detect changes to PDF annotations in iOS apps](/guides/ios/annotations/detecting-if-annotations-have-changed.md)
- [Setting annotation authors on iOS](/guides/ios/annotations/annotation-author-name.md)
- [Disable PDF annotation editing for iOS users](/guides/ios/annotations/create-edit-and-remove/disable-editing.md)
- [Drag-and-drop annotations on iOS](/guides/ios/annotations/create-edit-and-remove/drag-and-drop.md)
- [Programmatically create PDF annotations on iOS](/guides/ios/annotations/programmatically-creating-annotations.md)
- [Annotation state manager on iOS](/guides/ios/annotations/annotation-state-manager.md)
- [Undo and redo annotations on iOS](/guides/ios/features/undo-redo.md)
- [Z-index for annotation stacking order on iOS](/guides/ios/annotations/annotation-z-index.md)
- [Image picker: Add image annotations to PDFs on iOS](/guides/ios/miscellaneous/image-picker.md)

