org.faceless.pdf2

## Class EmbeddedFile

- java.lang.Object
- - org.faceless.pdf2.EmbeddedFile

- All Implemented Interfaces:
    Cloneable

      public final class EmbeddedFile
      extends Object

  This class represents a file which may be embedded into a PDF document, either by using the `AnnotationFile` class or through the `PDF.getEmbeddedFiles()` map.

  Since:
    2.6

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EmbeddedFile(File file)` Create a new EmbeddedFile object to embed the specified file.
    `EmbeddedFile(File file, String name)` Create a new EmbeddedFile object to embed the specified file.
    `EmbeddedFile(InputStream in, String name)` Set the content of this Embeddedfile to the specified InputStream.
    `EmbeddedFile(PDF pdf, String name)` Set the content of this EmbeddedFile to the specified PDF.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Date` | `getCreationDate()` Return the Creation Date of this file, or `null` if not specified.
    `InputStream` | `getData()` Return the attached file as an InputStream, or `null` if the file is not attached and is referenced by name only.
    `String` | `getDescription()` Return the description for this file as set by `setDescription(java.lang.String)`, or `null` if not set.
    `Date` | `getModDate()` Return the Last-modified Date of this file, or `null` if not specified.
    `String` | `getName()` Return the Filename of the file
    `String` | `getPortfolioFolder()` Return the name of the folder, as set by `setPortfolioFolder(java.lang.String)`
    `String` | `getRelationship()` Get the "associated file relationship" field.
    `int` | `getSize()` Return the size of the attached file, or -1 if not specified (note the file always has a size of course, but that size isn't always stored in the PDF.
    `String` | `getType()` Return the MIME type of this file attachment if specified, or `null` if not specified.
    `boolean` | `isValid()` Returns true if the file matches the stored checksum or if no checksum is specified.
    `void` | `setCreationDate(Date date)` Set the Creation Date of this file.
    `void` | `setDescription(String desc)` Set the optional description for this file.
    `void` | `setModDate(Date date)` Set the Last-modified Date of this file.
    `void` | `setPortfolioFolder(String foldername)` Set the name of the folder this EmbeddedFile should be stored in when the PDF is a `Portfolio`.
    `void` | `setRelationship(String name)` Set the "associated file relationship" field, which defines the relationship between this file attachment and the PDF.
    `void` | `setType(String mimetype)` Set the MIME type for this file attachment.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### EmbeddedFile

          public EmbeddedFile(File file)
                       throws IOException

      Create a new EmbeddedFile object to embed the specified file.
      Parameters:
        `file` - the file to embed
      Throws:
        `IOException`

    - #### EmbeddedFile

          public EmbeddedFile(File file,
                              String name)
                       throws IOException

      Create a new EmbeddedFile object to embed the specified file.
      Parameters:
        `file` - the file to embed
        `name` - the name to give the file
      Throws:
        `IOException`
      Since:
        2.14.1

    - #### EmbeddedFile

          public EmbeddedFile(InputStream in,
                              String name)
                       throws IOException

      Set the content of this Embeddedfile to the specified InputStream. The InputStream is read completely but not closed.
      Parameters:
        `in` - the InputStream to read from - must not be null
        `name` - the filename - must not be null
      Throws:
        `IOException`

    - #### EmbeddedFile

          public EmbeddedFile(PDF pdf,
                              String name)
                       throws IOException

      Set the content of this EmbeddedFile to the specified PDF. The PDF is rendered to a stream, and from there treated as an ordinary file. The MIME-type, creation and modification date are all set with this constructor.
      Parameters:
        `pdf` - the PDF to store as an embedded file.
        `name` - the "filename" of the PDF to use when storing it internally.
      Throws:
        `IOException`
      Since:
        2.7.8

  - ### Method Detail

    - #### getName

          public String getName()

      Return the Filename of the file

    - #### setType

          public void setType(String mimetype)

      Set the MIME type for this file attachment. This is optional but recommended, as it is not set automatically.
      Parameters:
        `mimetype` - the MIME type of the file

    - #### getType

          public String getType()

      Return the MIME type of this file attachment if specified, or `null` if not specified.

    - #### setDescription

          public void setDescription(String desc)

      Set the optional description for this file.
      Parameters:
        `desc` - the description to use

    - #### getDescription

          public String getDescription()

      Return the description for this file as set by `setDescription(java.lang.String)`, or `null` if not set.

    - #### setCreationDate

          public void setCreationDate(Date date)

      Set the Creation Date of this file. Java has no way to detemine the creation date of a file (many operating systems don't have this concept), so this attribute is not set automatically.
      Parameters:
        `date` - the Last-modified Date of this file

    - #### getCreationDate

          public Date getCreationDate()

      Return the Creation Date of this file, or `null` if not specified.

    - #### setModDate

          public void setModDate(Date date)

      Set the Last-modified Date of this file. When creating an `EmbeddedFile` from the `EmbeddedFile(File)` constructor, this value is initialised to the correct date.
      Parameters:
        `date` - the Last-modified Date of this file

    - #### getRelationship

          public String getRelationship()

      Get the "associated file relationship" field. This is an optional value in PDF 2.0 but is required in PDF/A-3 or later
      Since:
        2.14.1

    - #### setRelationship

          public void setRelationship(String name)

      Set the "associated file relationship" field, which defines the relationship between this file attachment and the PDF. This is an optional value in PDF 2.0 but required for PDF/A-3 or later. The value is normally one of "Source", "Data", "Alternative", "Supplement" or "Unspecified", but may be any value.
      Since:
        2.14.1

    - #### getModDate

          public Date getModDate()

      Return the Last-modified Date of this file, or `null` if not specified.

    - #### getSize

          public int getSize()

      Return the size of the attached file, or -1 if not specified (note the file always has a size of course, but that size isn't always stored in the PDF. If this method returns -1 there is no way to determine the size of the file without reading it).

    - #### getData

          public InputStream getData()

      Return the attached file as an InputStream, or `null` if the file is not attached and is referenced by name only.

    - #### isValid

          public boolean isValid()

      Returns true if the file matches the stored checksum or if no checksum is specified. Note most files are stored compressed using the Flate algorithm, which is self-checksumming, so this method is a little redundant. However the MD5 checksum optionally stored with embedded files is much stronger, so we provide this method for completeness.

      Note that if no checksum is stored this method returns `true`, so although a `false` definitely indicates a corrupt file, a `true` doesn't guarantee that it isn't corrupt.

      As this method calls the `getData()` method internally, the InputStream returned from that method must not be open prior to this call, otherwise the checksum will almost certainly fail.

    - #### setPortfolioFolder

          public void setPortfolioFolder(String foldername)

      Set the name of the folder this EmbeddedFile should be stored in when the PDF is a `Portfolio`. Folders are only supported in Acrobat X and later, and the folder name must be set before the EmbeddedFile is added to the `PDF.getEmbeddedFiles()` map.
      Parameters:
        `foldername` - the folder name - subfolders are delimetered with the "/" character, eg `/folder1/subfolder2`
      Throws:
        `IllegalStateException` - if this is called after this object is added to the PDF
      Since:
        2.14.1

    - #### getPortfolioFolder

          public String getPortfolioFolder()

      Return the name of the folder, as set by `setPortfolioFolder(java.lang.String)`
      Since:
        2.14.1

    - #### toString

          public String toString()

Copyright © 2001-2015 Big Faceless Organization