# Embed or attach a file to a PDF on Android

Nutrient supports embedding files inside PDF documents via file annotations. You can embed any file type, including PDFs that embed another PDF which, in turn, embeds a PDF, and so on. There’s also basic UI support for sharing files embedded in file annotations via Android’s share framework.

Embedding files can be a handy feature for various business cases. For example, you can embed a photo of a driver’s license in an application form (a PDF document) or an Excel file in a monthly report (a PDF document).

## Creating file annotations

[`FileAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-file-annotation/index.html) can be created programmatically in the same way as other supported annotations. The source for the embedded file needs to be wrapped in the [`EmbeddedFileSource`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.files/-embedded-file-source/index.html), and you’ll need to provide at least a [`DataProvider`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.providers/-data-provider/index.html) serving file data, and its name.

The following example shows how to create a file annotation with data served from application assets:

### KOTLIN

```kotlin

// Create a file annotation instance.
val fileAnnotation = FileAnnotation(
    // Page index 0.
    0,
    // Page rectangle (in PDF coordinates).
    RectF(180f, 692f, 212f, 660f),
    // Embedded file source serving file data from assets.
    EmbeddedFileSource(
        AssetDataProvider("FileInAssets.pdf"),
        "FileInAssets.pdf",
        "Optional file description"
    ))
// Multiple file icons are supported.
fileAnnotation.iconName = FileAnnotation.GRAPH
// Annotation color is supported too.
fileAnnotation.color = Color.GREEN

// Add the created file annotation to the page.
document.annotationProvider.addAnnotationToPage(fileAnnotation)

```

### JAVA

```java

// Create a file annotation instance.
final FileAnnotation fileAnnotation = new FileAnnotation(
    // Page index 0.
    0,
    // Page rectangle (in PDF coordinates).
    new RectF(180, 692, 212, 660),
    // Embedded file source serving file data from assets.
    new EmbeddedFileSource(
        new AssetDataProvider("FileInAssets.pdf"),
        "FileInAssets.pdf",
        "Optional file description"
    ));
// Multiple file icons are supported.
fileAnnotation.setIconName(FileAnnotation.GRAPH);
// Annotation color is supported too.
fileAnnotation.setColor(Color.GREEN);

// Add the created file annotation to the page.
document.getAnnotationProvider().addAnnotationToPage(fileAnnotation);

```

For additional examples, take a look at `FileAnnotationCreationExample` inside the Catalog app.
---

## Related pages

- [Define annotation behavior with flags on Android](/guides/android/annotations/annotation-flags.md)
- [Detect if an annotation has changed on Android](/guides/android/annotations/create-edit-and-remove/detect-changes.md)
- [Undo and redo annotations on Android](/guides/android/features/undo-redo.md)
- [Set annotation author names on Android easily](/guides/android/annotations/annotation-author-name.md)
- [Z-Index for annotation stacking order on Android](/guides/android/annotations/annotation-z-index.md)
- [Disabling annotation editing on Android](/guides/android/annotations/configuring-annotation-editing.md)
- [Programmatically create annotations on Android](/guides/android/annotations/programmatically-creating-annotations.md)
- [Copy and paste annotations on Android](/guides/android/features/copy-paste.md)

