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.
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.
|
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() |
public EmbeddedFile(File file) throws IOException
file
- the file to embedIOException
public EmbeddedFile(File file, String name) throws IOException
file
- the file to embedname
- the name to give the fileIOException
public EmbeddedFile(InputStream in, String name) throws IOException
in
- the InputStream to read from - must not be nullname
- the filename - must not be nullIOException
public EmbeddedFile(PDF pdf, String name) throws IOException
pdf
- the PDF to store as an embedded file.name
- the "filename" of the PDF to use when storing it internally.IOException
public String getName()
public void setType(String mimetype)
mimetype
- the MIME type of the filepublic String getType()
null
if
not specified.public void setDescription(String desc)
desc
- the description to usepublic String getDescription()
setDescription(java.lang.String)
,
or null
if not set.public void setCreationDate(Date date)
date
- the Last-modified Date of this filepublic Date getCreationDate()
null
if not specified.public void setModDate(Date date)
EmbeddedFile
from the EmbeddedFile(File)
constructor, this value is initialised to the
correct date.date
- the Last-modified Date of this filepublic String getRelationship()
public void setRelationship(String name)
public Date getModDate()
null
if not specified.public int getSize()
public InputStream getData()
null
if the file
is not attached and is referenced by name only.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.
public void setPortfolioFolder(String foldername)
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.foldername
- the folder name - subfolders are delimetered with the "/" character, eg /folder1/subfolder2
IllegalStateException
- if this is called after this object is added to the PDFpublic String getPortfolioFolder()
setPortfolioFolder(java.lang.String)
public String toString()
Copyright © 2001-2017 Big Faceless Organization