| Constructor: |
public PRStream(PRStream stream,
PdfDictionary newDic) {
reader = stream.reader;
offset = stream.offset;
length = stream.length;
compressed = stream.compressed;
compressionLevel = stream.compressionLevel;
streamBytes = stream.streamBytes;
bytes = stream.bytes;
objNum = stream.objNum;
objGen = stream.objGen;
if (newDic != null)
putAll(newDic);
else
hashMap.putAll(stream.hashMap);
}
|
public PRStream(PdfReader reader,
int offset) {
this.reader = reader;
this.offset = offset;
}
|
public PRStream(PdfReader reader,
byte[] conts) {
this(reader, conts, DEFAULT_COMPRESSION);
}
|
public PRStream(PRStream stream,
PdfDictionary newDic,
PdfReader reader) {
this(stream, newDic);
this.reader = reader;
}
|
public PRStream(PdfReader reader,
byte[] conts,
int compressionLevel) {
this.reader = reader;
this.offset = -1;
if (Document.compress) {
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DeflaterOutputStream zip = new DeflaterOutputStream(stream, new Deflater(compressionLevel));
zip.write(conts);
zip.close();
bytes = stream.toByteArray();
}
catch (IOException ioe) {
throw new ExceptionConverter(ioe);
}
put(PdfName.FILTER, PdfName.FLATEDECODE);
}
else
bytes = conts;
setLength(bytes.length);
}
Creates a new PDF stream object that will replace a stream
in a existing PDF file. Parameters:
reader - the reader that holds the existing PDF
conts - the new content
compressionLevel - the compression level for the content
- since:
2.1.3 - (replacing the existing constructor without param compressionLevel)
|
| Method from com.lowagie.text.pdf.PRStream Detail: |
public byte[] getBytes() {
return bytes;
}
|
public int getLength() {
return length;
}
|
int getObjGen() {
return objGen;
}
|
int getObjNum() {
return objNum;
}
|
public int getOffset() {
return offset;
}
|
public PdfReader getReader() {
return reader;
}
|
public void setData(byte[] data) {
setData(data, true);
}
Sets the data associated with the stream |
public void setData(byte[] data,
boolean compress) {
setData(data, compress, DEFAULT_COMPRESSION);
}
Sets the data associated with the stream, either compressed or
uncompressed. Note that the data will never be compressed if
Document.compress is set to false. |
public void setData(byte[] data,
boolean compress,
int compressionLevel) {
remove(PdfName.FILTER);
this.offset = -1;
if (Document.compress && compress) {
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DeflaterOutputStream zip = new DeflaterOutputStream(stream, new Deflater(compressionLevel));
zip.write(data);
zip.close();
bytes = stream.toByteArray();
this.compressionLevel = compressionLevel;
}
catch (IOException ioe) {
throw new ExceptionConverter(ioe);
}
put(PdfName.FILTER, PdfName.FLATEDECODE);
}
else
bytes = data;
setLength(bytes.length);
}
Sets the data associated with the stream, either compressed or
uncompressed. Note that the data will never be compressed if
Document.compress is set to false. |
public void setLength(int length) {
this.length = length;
put(PdfName.LENGTH, new PdfNumber(length));
}
|
public void setObjNum(int objNum,
int objGen) {
this.objNum = objNum;
this.objGen = objGen;
}
|
public void toPdf(PdfWriter writer,
OutputStream os) throws IOException {
byte[] b = PdfReader.getStreamBytesRaw(this);
PdfEncryption crypto = null;
if (writer != null)
crypto = writer.getEncryption();
PdfObject objLen = get(PdfName.LENGTH);
int nn = b.length;
if (crypto != null)
nn = crypto.calculateStreamSize(nn);
put(PdfName.LENGTH, new PdfNumber(nn));
superToPdf(writer, os);
put(PdfName.LENGTH, objLen);
os.write(STARTSTREAM);
if (length > 0) {
if (crypto != null && !crypto.isEmbeddedFilesOnly())
b = crypto.encryptByteArray(b);
os.write(b);
}
os.write(ENDSTREAM);
}
|