Skip to main content

FileSpecification Class

Contains metadata and binary data for a file associated with a PDF document.

Declaration

public class FileSpecification extends JavaObject implements ICloneable

Remarks

Use the setFileSpecification(FileSpecification value) method to a attach a file to the annotation.

Create a FileSpecification object, specify the file name, load the file data, and assign the file specification to the annotation.

The following code snippet attaches a file to a PDF page and displays it with a paper clip icon:

 File Attachment Annotation, DevExpress PDF Document API for Java

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.

Implements

com.devexpress.system.ICloneable

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
FileSpecification

FileSpecification()

Initializes a new instance of the FileSpecification class.

Declaration

public FileSpecification()

Methods

clone(DocumentCloneContext context) Method

Creates a copy of the file specification in the specified document clone context.

Declaration

public FileSpecification clone(DocumentCloneContext context)

Parameters

Name Type Description
context DocumentCloneContext

The document clone context.

Returns

Type Description
FileSpecification

A copy of the file specification.

deepClone() Method

Creates a deep copy of the file specification.

Declaration

public FileSpecification deepClone()

Returns

Type Description
FileSpecification

A deep copy of the file specification.

getCreationDate() Method

Returns the file creation date.

Declaration

public OffsetDateTime getCreationDate()

Returns

Type Description
OffsetDateTime

The file creation date.

getDescription() Method

Returns the file description.

Declaration

public String getDescription()

Returns

Type Description
String

The file description.

getFileData() Method

Returns the file binary data.

Declaration

public byte[] getFileData()

Returns

Type Description
byte[]

The file binary data.

getFileName() Method

Returns the file name.

Declaration

public String getFileName()

Returns

Type Description
String

The file name.

getFileSystem() Method

Returns the file system name.

Declaration

public String getFileSystem()

Returns

Type Description
String

The file system name.

getIndex() Method

Returns the file specification index.

Declaration

public int getIndex()

Returns

Type Description
int

The file specification index.

getMimeType() Method

Returns the file MIME type.

Declaration

public String getMimeType()

Returns

Type Description
String

The file MIME type.

getModificationDate() Method

Returns the file modification date.

Declaration

public OffsetDateTime getModificationDate()

Returns

Type Description
OffsetDateTime

The file modification date.

getRelationship() Method

Returns the associated file relationship.

Declaration

public AssociatedFileRelationship getRelationship()

Returns

Type Description
AssociatedFileRelationship

The associated file relationship.

getSize() Method

Returns the file size.

Declaration

public int getSize()

Returns

Type Description
int

The file size, in bytes.

objectClone() Method

Creates an object copy of the file specification.

Declaration

public Object objectClone()

Returns

Type Description
Object

A copy of the file specification.

setCreationDate(OffsetDateTime value) Method

Sets the file creation date.

Declaration

public void setCreationDate(OffsetDateTime value)

Parameters

Name Type Description
value OffsetDateTime

The file creation date.

setDescription(String value) Method

Sets the file description.

Declaration

public void setDescription(String value)

Parameters

Name Type Description
value String

The file description.

setFileData(byte[] value) Method

Sets the file binary data.

Declaration

public void setFileData(byte[] value)

Parameters

Name Type Description
value byte[]

The file binary data.

setFileName(String value) Method

Sets the file name.

Declaration

public void setFileName(String value)

Parameters

Name Type Description
value String

The file name.

setFileSystem(String value) Method

Sets the file system name.

Declaration

public void setFileSystem(String value)

Parameters

Name Type Description
value String

The file system name.

setIndex(int value) Method

Sets the file specification index.

Declaration

public void setIndex(int value)

Parameters

Name Type Description
value int

The file specification index.

setMimeType(String value) Method

Sets the file MIME type.

Declaration

public void setMimeType(String value)

Parameters

Name Type Description
value String

The file MIME type.

setModificationDate(OffsetDateTime value) Method

Sets the file modification date.

Declaration

public void setModificationDate(OffsetDateTime value)

Parameters

Name Type Description
value OffsetDateTime

The file modification date.

setRelationship(AssociatedFileRelationship value) Method

Sets the associated file relationship.

Declaration

public void setRelationship(AssociatedFileRelationship value)

Parameters

Name Type Description
value AssociatedFileRelationship

The associated file relationship.

setSize(int value) Method

Sets the file size.

Declaration

public void setSize(int value)

Parameters

Name Type Description
value int

The file size, in bytes.