A PDStream represents a stream in a PDF document. Streams are tied to a single
PDF document.
PDStream
protected PDStream()
This will create a new PDStream object.
PDStream
public PDStream(COSStream str)
Constructor.
str
- The stream parameter.
PDStream
public PDStream(PDDocument document)
This will create a new PDStream object.
document
- The document that the stream will be part of.
PDStream
public PDStream(PDDocument doc,
InputStream str)
throws IOException
Constructor. Reads all data from the input stream and embeds it into the
document, this will close the InputStream.
doc
- The document that will hold the stream.str
- The stream parameter.
PDStream
public PDStream(PDDocument doc,
InputStream str,
boolean filtered)
throws IOException
Constructor. Reads all data from the input stream and embeds it into the
document, this will close the InputStream.
doc
- The document that will hold the stream.str
- The stream parameter.filtered
- True if the stream already has a filter applied.
addCompression
public void addCompression()
If there are not compression filters on the current stream then this
will add a compression filter, flate compression for example.
createFromCOS
public static PDStream createFromCOS(COSBase base)
throws IOException
Create a pd stream from either a regular COSStream on a COSArray of cos streams.
base
- Either a COSStream or COSArray.
- A PDStream or null if base is null.
createInputStream
public InputStream createInputStream()
throws IOException
This will get a stream that can be read from.
- An input stream that can be read from.
createOutputStream
public OutputStream createOutputStream()
throws IOException
This will get a stream that can be written to.
- An output stream to write data to.
getByteArray
public byte[] getByteArray()
throws IOException
This will copy the stream into a byte array.
- The byte array of the filteredStream
getCOSObject
public COSBase getCOSObject()
Convert this standard java object to a COS object.
- getCOSObject in interface COSObjectable
- The cos object that matches this Java object.
getDecodeParams
public List getDecodeParams()
throws IOException
Get the list of decode parameters. Each entry in the list will refer to
an entry in the filters list.
- The list of decode parameters.
getFile
public PDFileSpecification getFile()
throws IOException
This will get the file specification for this stream. This is only
required for external files.
getFileDecodeParams
public List getFileDecodeParams()
throws IOException
Get the list of decode parameters. Each entry in the list will refer to
an entry in the filters list.
- The list of decode parameters.
getFileFilters
public List getFileFilters()
This will get the list of filters that are associated with this stream. Or
null if there are none.
- A list of all encoding filters to apply to this stream.
getFilters
public List getFilters()
This will get the list of filters that are associated with this stream. Or
null if there are none.
- A list of all encoding filters to apply to this stream.
getInputStreamAsString
public String getInputStreamAsString()
throws IOException
A convenience method to get this stream as a string. Uses
the default system encoding.
- a String representation of this (input) stream, with the
platform default encoding.
getLength
public int getLength()
This will get the length of the filtered/compressed stream. This is readonly in the
PD Model and will be managed by this class.
- The length of the filtered stream.
getMetadata
public PDMetadata getMetadata()
Get the metadata that is part of the document catalog. This will
return null if there is no meta data for this object.
- The metadata for this object.
getPartiallyFilteredStream
public InputStream getPartiallyFilteredStream(List stopFilters)
throws IOException
This will get a stream with some filters applied but not others. This is useful
when doing images, ie filters = [flate,dct], we want to remove flate but leave dct
stopFilters
- A list of filters to stop decoding at.
- A stream with decoded data.
getStream
public COSStream getStream()
Get the cos stream associated with this object.
- The cos object that matches this Java object.
setDecodeParams
public void setDecodeParams(List decodeParams)
This will set the list of decode params.
decodeParams
- The list of decode params.
setFile
public void setFile(PDFileSpecification f)
Set the file specification.
f
- The file specification.
setFileDecodeParams
public void setFileDecodeParams(List decodeParams)
This will set the list of decode params.
decodeParams
- The list of decode params.
setFileFilters
public void setFileFilters(List filters)
This will set the filters that are part of this stream.
filters
- The filters that are part of this stream.
setFilters
public void setFilters(List filters)
This will set the filters that are part of this stream.
filters
- The filters that are part of this stream.
setMetadata
public void setMetadata(PDMetadata meta)
Set the metadata for this object. This can be null.
meta
- The meta data for this object.