Class PdfStream
- Direct Known Subclasses:
BaseFont.StreamFont, PdfContents, PdfFormXObject, PdfPattern, PRStream
PdfStream is the Pdf stream object.
A stream, like a string, is a sequence of characters. However, an application can
read a small portion of a stream at a time, while a string must be read in its entirety.
For this reason, objects with potentially large amounts of data, such as images and
page descriptions, are represented as streams.
A stream consists of a dictionary that describes a sequence of characters, followed by
the keyword stream, followed by zero or more lines of characters, followed by
the keyword endstream.
All streams must be PdfIndirectObjects. The stream dictionary must be a direct
object. The keyword stream that follows the stream dictionary should be followed by
a carriage return and linefeed or just a linefeed.
Remark: In this version only the FLATEDECODE-filter is supported.
This object is described in the 'Portable Document Format Reference Manual version 1.7'
section 3.2.7 (page 60-63).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA possible compression level.static final intA possible compression level.protected booleanis the stream compressed?protected intThe level of compression.static final intA possible compression level.(package private) static final byte[]protected InputStreamprotected intstatic final intA possible compression level.protected intprotected PdfIndirectReference(package private) static final int(package private) static final byte[]protected ByteArrayOutputStreamprotected PdfWriter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs aPdfStream-object.PdfStream(byte[] bytes) Constructs aPdfStream-object.PdfStream(InputStream inputStream, PdfWriter writer) Creates an efficient stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidCompresses the stream.voidflateCompress(int compressionLevel) Compresses the stream.intGets the raw length of the stream.protected voidsuperToPdf(PdfWriter writer, OutputStream os) voidtoPdf(PdfWriter writer, OutputStream os) Returns the PDF representation of thisPdfDictionary.toString()Returns theString-representation of thisPdfObject.voidWrites the data content to anOutputStream.voidWrites the stream length to thePdfWriter.Methods inherited from class PdfDictionary
contains, get, getAsArray, getAsBoolean, getAsDict, getAsIndirectObject, getAsName, getAsNumber, getAsStream, getAsString, getDirectObject, getKeys, isCatalog, isDictionaryType, isFont, isOutlineTree, isPage, isPages, merge, mergeDifferent, put, putAll, putDel, putEx, remove, sizeMethods inherited from class PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, type
-
Field Details
-
DEFAULT_COMPRESSION
public static final int DEFAULT_COMPRESSIONA possible compression level.- Since:
- 2.1.3
- See Also:
-
NO_COMPRESSION
public static final int NO_COMPRESSIONA possible compression level.- Since:
- 2.1.3
- See Also:
-
BEST_SPEED
public static final int BEST_SPEEDA possible compression level.- Since:
- 2.1.3
- See Also:
-
BEST_COMPRESSION
public static final int BEST_COMPRESSIONA possible compression level.- Since:
- 2.1.3
- See Also:
-
compressed
protected boolean compressedis the stream compressed? -
compressionLevel
protected int compressionLevelThe level of compression.- Since:
- 2.1.3
-
streamBytes
-
inputStream
-
ref
-
inputStreamLength
protected int inputStreamLength -
writer
-
rawLength
protected int rawLength -
STARTSTREAM
static final byte[] STARTSTREAM -
ENDSTREAM
static final byte[] ENDSTREAM -
SIZESTREAM
static final int SIZESTREAM
-
-
Constructor Details
-
PdfStream
public PdfStream(byte[] bytes) Constructs aPdfStream-object.- Parameters:
bytes- content of the newPdfObjectas an array ofbyte.
-
PdfStream
Creates an efficient stream. No temporary array is ever created. TheInputStreamis totally consumed but is not closed. The general usage is:InputStream in = ...; PdfStream stream = new PdfStream(in, writer); stream.flateCompress(); writer.addToBody(stream); stream.writeLength(); in.close();
- Parameters:
inputStream- the data to write to this streamwriter- thePdfWriterfor this stream
-
PdfStream
protected PdfStream()Constructs aPdfStream-object.
-
-
Method Details
-
writeLength
Writes the stream length to thePdfWriter.This method must be called and can only be called if the constructor
PdfStream(InputStream,PdfWriter)is used to create the stream.- Throws:
IOException- on error- See Also:
-
getRawLength
public int getRawLength()Gets the raw length of the stream.- Returns:
- the raw length of the stream
-
flateCompress
public void flateCompress()Compresses the stream. -
flateCompress
public void flateCompress(int compressionLevel) Compresses the stream.- Parameters:
compressionLevel- the compression level (0 = best speed, 9 = best compression, -1 is default)- Since:
- 2.1.3
-
superToPdf
- Throws:
IOException
-
toPdf
Description copied from class:PdfDictionaryReturns the PDF representation of thisPdfDictionary.- Overrides:
toPdfin classPdfDictionary- Parameters:
writer- for backwards compatibilityos- the outputstream to write the bytes to.- Throws:
IOException- See Also:
-
writeContent
Writes the data content to anOutputStream.- Parameters:
os- the destination to write to- Throws:
IOException- on error
-
toString
-