# FileAttachment Class

> A file attachment.Any file can be attached to the PDF document.

- Product: Adobe PDF Library 18
- Language: Java
- Version: APDFL18.0.5PlusP2e
- HTML page: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/FileAttachment
- Version index: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/llms.txt

```java
class FileAttachment
```

**Namespace:** `com::datalogics::PDFL`

## Description

A file attachment.Any file can be attached to the PDF document. The class allows to create attachment and manipulate by its content.

**Referenced by:** [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md), [`FileAttachmentPtrVector`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/FileAttachmentPtrVector.md)

**Uses types:** [`CollectionSchemaField`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CollectionSchemaField.md), [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md), [`JavaStreamFile`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/JavaStreamFile.md)

## Constructors

### FileAttachment

```java
com.datalogics.PDFL.FileAttachment.FileAttachment(Document doc, String fileName)
```

*constructor*

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The PDF document (reference).
- `fileName` (`String`): The path to file which will be attached to the document.

Allows to add attachment into the PDF document.

### FileAttachment

```java
com.datalogics.PDFL.FileAttachment.FileAttachment(Document doc, String fileName, String keyName)
```

*constructor*

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The PDF document (reference).
- `fileName` (`String`): The path to file which will be attached to the document.
- `keyName` (`String`): The name of the key.

Allows to add attachment into the PDF document using the specified key name.

## Methods

### delete

```java
synchronized void com.datalogics.PDFL.FileAttachment.delete(Boolean disposing)
```

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

```java
synchronized void com.datalogics.PDFL.FileAttachment.delete()
```

**Returns:** `synchronized void`

### finalize

```java
void com.datalogics.PDFL.FileAttachment.finalize()
```

*protected*

**Returns:** `void`

### getAFRelationship

```java
AFRelationship com.datalogics.PDFL.FileAttachment.getAFRelationship()
```

**Returns:** `AFRelationship`

The attachment's Associated File relationship.

Gets the attachment's Associated File relationship.

### getCollectionItemNumber

```java
float com.datalogics.PDFL.FileAttachment.getCollectionItemNumber(CollectionSchemaField collectionField)
```

**Parameters**

- `collectionField` ([`CollectionSchemaField`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CollectionSchemaField.md)): the field for which item value should be retrieved.

**Returns:** `float`

collection items value

GetCollectionItemNumber allows to obtain collection item according to the specified schema field.

### getCollectionItemString

```java
String com.datalogics.PDFL.FileAttachment.getCollectionItemString(CollectionSchemaField collectionField)
```

**Parameters**

- `collectionField` ([`CollectionSchemaField`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CollectionSchemaField.md)): the field for which item value should be retrieved.

**Returns:** `String`

collection items value

GetCollectionItemString allows to obtain collection item value according to the specified schema field.

### getFileName

```java
String com.datalogics.PDFL.FileAttachment.getFileName()
```

**Returns:** `String`

The attachment's file name.

Gets the attachment's file name.

### getFileSize

```java
long com.datalogics.PDFL.FileAttachment.getFileSize()
```

**Returns:** `long`

The attachment's size in bytes.

Gets the attachment's file size.

### saveToFile

```java
void com.datalogics.PDFL.FileAttachment.saveToFile(String fileName)
```

**Parameters**

- `fileName` (`String`): The path where attachment will be saved.

**Returns:** `void`

Allows to save attachment to the specified file.

### saveToStream

```java
void com.datalogics.PDFL.FileAttachment.saveToStream(javax.imageio.stream.ImageOutputStream stream)
```

**Parameters**

- `stream` (`javax.imageio.stream.ImageOutputStream`): The stream from which to save the FileAttachment.

**Returns:** `void`

Saves a FileAttachment to a javax.imageio.stream.ImageInputStream.

### setAFRelationship

```java
void com.datalogics.PDFL.FileAttachment.setAFRelationship(AFRelationship relationship)
```

**Parameters**

- `relationship` (`AFRelationship`): The Associated File relationship to set.

**Returns:** `void`

Sets the attachment's Associated File relationship.

### setCollectionItemNumber

```java
void com.datalogics.PDFL.FileAttachment.setCollectionItemNumber(CollectionSchemaField collectionField, float value)
```

**Parameters**

- `collectionField` ([`CollectionSchemaField`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CollectionSchemaField.md)): schema field which contains information about data type. The parameter's subtype should be a Number.
- `value` (`float`): the item's value.

**Returns:** `void`

SetCollectionItemNumber allows to add key to the collection item dictionary.

### setCollectionItemString

```java
void com.datalogics.PDFL.FileAttachment.setCollectionItemString(CollectionSchemaField collectionField, String value)
```

**Parameters**

- `collectionField` ([`CollectionSchemaField`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CollectionSchemaField.md)): schema field which contains information about data type. The parameter's subtype should be a Text.
- `value` (`String`): the item's value.

**Returns:** `void`

SetCollectionItemString allows to add key to the collection item dictionary.

### updateFromFile

```java
void com.datalogics.PDFL.FileAttachment.updateFromFile(String fileName)
```

**Parameters**

- `fileName` (`String`): The path to the file from which attachment will be updated.

**Returns:** `void`

Allows to update attachment from another file.
