> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/annotation/annotation-types/fileattachmentannotation.md).

# File Attachment Annotations

Enhance document interactivity with file attachment annotations. Annotate files within documents, download them, and maintain consistent size and orientation across zoom levels. Explore customization

File attachment annotations are annotations that represent an attached file in the document. Users can annotate their documents with files that can also be downloaded.

File attachment are created with `NoZoom` and `NoRotate` set to `true` by default. This means they will remain the same size at all zoom levels and will not rotate with the view/page. Stroke color is also used as the primary color of the icons as opposed to fill color.

In the PDF specification, there are no specifications for file restrictions or attachment size limits. WebViewer has provided options to tweaks these from the [tool](https://sdk.apryse.com/api/web/Core.Tools.FileAttachmentCreateTool.html) that creates file attachment annotations.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-f9b8df3b15a44e064d5294e0c06cbfd82a9d5efa%2Fcb6af512efd6bfd84ff33ace775e5675106ac73e-197x133.png?alt=media)

## Instantiation

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager, Annotations } = instance.Core;
    documentViewer.addEventListener('annotationsLoaded', async () => {
      const annot = new Annotations.FileAttachmentAnnotation({
        PageNumber: 1,
        X: 100,
        Y: 50,
        Icon: 'Paperclip',
        StrokeColor: new Annotations.Color(0, 255, 0, 1),
      });
      
      const res = await fetch('https://myserver.com/files/test.pdf');
      const buffer = await res.arrayBuffer();
      await annot.setFileData(buffer, 'application/pdf', 'test.pdf');
      annotationManager.addAnnotation(annot);
      annotationManager.redrawAnnotation(annot);
    });
  });
```

{% endcode %}

[DocumentViewer#annotationsLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:annotationsLoaded) [FileAttachmentAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html) [Color](https://sdk.apryse.com/api/web/Core.Annotations.Color.html) [setFileData](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#setFileData) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation) [AnnotationManager.redrawAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#redrawAnnotation)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;
    docViewer.on('annotationsLoaded', () => {
      const annot = new Annotations.FileAttachmentAnnotation();
      annot.PageNumber = 1;
      annot.X = 100;
      annot.Y = 50;
      annot.Icon = 'Paperclip';
      annot.StrokeColor = new Annotations.Color(0, 255, 0, 1);
      
      const res = await fetch('https://myserver.com/files/test.pdf');
      const buffer = await res.arrayBuffer();
      await annot.setFileData(buffer, 'application/pdf', 'test.pdf');
      annotManager.addAnnotation(annot);
      annotManager.redrawAnnotation(annot);
    });
  });
```

{% endcode %}

[DocumentViewer#annotationsLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:annotationsLoaded) [FileAttachmentAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html) [Color](https://sdk.apryse.com/api/web/Core.Annotations.Color.html) [setFileData](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#setFileData) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation) [AnnotationManager.redrawAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#redrawAnnotation)
{% endtab %}
{% endtabs %}

## XFDF

Element name: `fileattachment`

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
<fileattachment page="0" rect="302.410,609.110,316.410,643.110" color="#000000" flags="print,nozoom,norotate" name="c93af20d-a823-b04b-6cae-de26e3202304" title="Guest" subject="File Attachment" date="D:20220721151359-07'00'" creationdate="D:20220721151349-07'00'" icon="Paperclip" mimetype="application/pdf" file="test.pdf">
  <data mode="raw" filter="FlateDecode" encoding="hex" length="4561">...</data>
</fileattachment>
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Required properties

### PageNumber

Gets or sets the page number of a document that the annotation appears on.

### X

Gets or sets the annotation's x-axis position.

### Y

Gets or sets the annotation's y-axis position.

## Notable properties

For the full list of properties, please visit the annotation's [API docs](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html).

### Icon

The name of the icon to use for this file attachment annotation. Possible default icon types:

* Graph
* PushPin
* Paperclip
* Tag

### Author

The author of the annotation.

### Color

Gets or sets the annotation's stroke color.

### Hidden

Gets or sets whether the annotation is hidden.

### Invisible

Gets or sets whether the annotation is invisible, only if it is an unknown annotation type. Generally for hiding annotations you should use "Hidden".

### IsClickableOutsideRect

Gets or sets whether any parts of the annotation drawn outside of the rect are clickable.

### Listable

Gets or sets whether the annotation should be listed in annotation lists. If set to false, the annotation will also become unselectable.

### Locked

Gets or sets whether the annotation is locked or not. If it's locked it can't be edited or deleted, but the note can be edited.

### LockedContents

Gets or sets whether the annotation contents are locked or not. If the contents are locked then note can't be edited but the annotation can be edited or deleted.

### NoDelete

Gets or sets if this annotation can be deleted.

### NoMove

Gets or sets whether or not the annotation can be moved.

### NoResize

Gets or sets if this annotation can be resized by the user.

### NoRotate

Gets or sets if this annotation can be rotated.

### NoView

Gets or sets whether the annotation is visible on the screen. Differs from Hidden in that it can still be printed if the print flag is set.

### NoZoom

Gets or sets if this annotation scales with the page.

### Opacity

Gets or sets the opacity of the annotation.

### Printable

Gets or sets whether the annotation should be displayed when printing the page.

### ReadOnly

Gets or sets whether the annotation is readonly or not. If it's readonly both the annotation itself and its note can't be edited or deleted.

### StrokeColor

Gets or sets the color of the annotation's stroke.

### ToggleNoView

Gets or sets whether the ToggleNoView flag is set on the annotation.

## Useful methods

### getFileData

To get the file data from an attachment annotation, you can use [`getFileData`](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#getFileData) which will asynchronously return the data as a blob. This can be used to trigger an automatic download of an attachment.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager, Annotations } = instance.Core;
    documentViewer.addEventListener('annotationsLoaded', () => {
      const annotList = annotationManager.getAnnotationsList();
      annotList.forEach(async annot => {
        if (annot instanceof Annotations.FileAttachmentAnnotation) {
          const fileData = await annot.getFileData();
          const url = URL.createObjectURL(fileData);
          window.open(url);
        }
      });
    });
  });
```

{% endcode %}

[getFileData](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#getFileData)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager, Annotations } = instance.Core;
    documentViewer.addEventListener('annotationsLoaded', () => {
      const annotList = annotationManager.getAnnotationsList();
      annotList.forEach(async annot => {
        if (annot instanceof Annotations.FileAttachmentAnnotation) {
          const fileData = await annot.getFileData();
          const url = URL.createObjectURL(fileData);
          window.open(url);
        }
      });
    });
  });
```

{% endcode %}

[getFileData](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#getFileData)
{% endtab %}
{% endtabs %}

### setFileData

Setting the file data on a file attachment annotation is recommended after construction using [`setFileData`](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#setFileData). This requires slightly more information other than just the file data, as you will need to provide the web mimetype of the attachment and filename. The filename can be different and will be used when downloaded.

### getFileMetadata

If you need to understand the type of file that is stored in the attachment, you use [`getFileMetadata`](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#getFileMetadata) to get the mimetype and name of the file from when it was originally attached.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager, Annotations } = instance.Core;
    documentViewer.addEventListener('annotationsLoaded', () => {
      const annotList = annotationManager.getAnnotationsList();
      annotList.forEach(async annot => {
        if (annot instanceof Annotations.FileAttachmentAnnotation) {
          const metadata = annot.getFileMetadata();
          console.log(metadata.filename, metadata.mimeType);
        }
      });
    });
  });
```

{% endcode %}

[getFileData](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#getFileData)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer, annotationManager, Annotations } = instance.Core;
    documentViewer.addEventListener('annotationsLoaded', () => {
      const annotList = annotationManager.getAnnotationsList();
      annotList.forEach(async annot => {
        if (annot instanceof Annotations.FileAttachmentAnnotation) {
          const metadata = annot.getFileMetadata();
          console.log(metadata.filename, metadata.mimeType);
        }
      });
    });
  });
```

{% endcode %}

[getFileData](https://sdk.apryse.com/api/web/Core.Annotations.FileAttachmentAnnotation.html#getFileData)
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/annotation/annotation-types/fileattachmentannotation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
