FileAttachmentAnnotation Class
Defines a file attachment annotation in a PDF document.
Declaration
public class FileAttachmentAnnotation extends MarkupAnnotation
Remarks
A file attachment annotation embeds a file into a PDF document and displays an icon that users can click to open or extract the attached file.
Use the FileAttachmentAnnotation class to create a file attachment annotation. Specify annotation bounds, assign the embedded file with the FileSpecification object, and optionally change the annotation icon.
The following code snippet attaches a file to a PDF page and displays it with a paper clip icon:

package pdf;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
import java.nio.channels.*;
import java.nio.file.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
try (FileChannel fileChannel = FileChannel.open(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(fileChannel)) {
Page page = pdfDocument.getPages().getFirst();
createFileAttachmentAnnotation(page);
try (WritableByteChannel channel =
FileChannel.open(Path.of("Result.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(channel);
}
}
}
static void createFileAttachmentAnnotation(Page page) {
FileAttachmentAnnotation annotation =
new FileAttachmentAnnotation(
new RectangleF(50, 420, 20, 20));
annotation.setTitle("John Smith");
annotation.setContent("Project specification");
annotation.setIconName(FileAttachmentAnnotationIconName.PAPER_CLIP);
try {
FileSpecification fileSpecification = new FileSpecification();
fileSpecification.setFileName("Specification.pdf");
fileSpecification.setFileData(
Files.readAllBytes(Path.of("Specification.pdf")));
fileSpecification.setDescription("Project specification");
annotation.setFileSpecification(fileSpecification);
page.getAnnotations().add(annotation);
} catch (IOException e) {
throw new UncheckedIOException("Failed to read the attachment file.", e);
}
}
}
Refer to the following help topic for additional information: File and Multimedia Annotations.
Inherited Members
Inheritance
FileAttachmentAnnotation(RectangleF bounds)
Initializes a new instance of the FileAttachmentAnnotation class with specified bounds.
Declaration
public FileAttachmentAnnotation(RectangleF bounds)
Parameters
| Name | Type | Description |
|---|---|---|
| bounds | RectangleF | The annotation bounds. |
Methods
getFileSpecification() Method
Returns the file specification associated with the file attachment annotation.
Declaration
public FileSpecification getFileSpecification()
Returns
| Type | Description |
|---|---|
| FileSpecification | The file specification. |
getIconName() Method
Returns the file attachment annotation icon name.
Declaration
public FileAttachmentAnnotationIconName getIconName()
Returns
| Type | Description |
|---|---|
| FileAttachmentAnnotationIconName | The icon name. |
setFileSpecification(FileSpecification value) Method
Sets the file specification associated with the file attachment annotation.
Declaration
public void setFileSpecification(FileSpecification value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FileSpecification | The file specification. |
setIconName(FileAttachmentAnnotationIconName value) Method
Sets the file attachment annotation icon name.
Declaration
public void setIconName(FileAttachmentAnnotationIconName value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FileAttachmentAnnotationIconName | The icon name. |