public Write ( byte b, int off, int len ) : void | ||
b | byte | |
off | int | |
len | int | |
Результат | void |
/** * Compresses the stream. * @param compressionLevel the compression level (0 = best speed, 9 = best compression, -1 is default) * @since 2.1.3 */ public void FlateCompress(int compressionLevel) { if (!Document.Compress) return; // check if the flateCompress-method has allready been if (compressed) { return; } this.compressionLevel = compressionLevel; if (inputStream != null) { compressed = true; return; } // check if a filter allready exists PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER)); if (filter != null) { if (filter.IsName()) { if (PdfName.FLATEDECODE.Equals(filter)) return; } else if (filter.IsArray()) { if (((PdfArray) filter).Contains(PdfName.FLATEDECODE)) return; } else { throw new PdfException("Stream could not be compressed: filter is not a name or array."); } } // compress MemoryStream stream = new MemoryStream(); var zip = new ZOutputStream(stream, compressionLevel); if (streamBytes != null) streamBytes.WriteTo(zip); else zip.Write(bytes, 0, bytes.Length); //zip.Close(); zip.Finish(); // update the object streamBytes = stream; bytes = null; Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length)); if (filter == null) { Put(PdfName.FILTER, PdfName.FLATEDECODE); } else { PdfArray filters = new PdfArray(filter); filters.Add(PdfName.FLATEDECODE); Put(PdfName.FILTER, filters); } compressed = true; }
/** * Creates a new PDF stream object that will replace a stream * in a existing PDF file. * @param reader the reader that holds the existing PDF * @param conts the new content * @param compressionLevel the compression level for the content * @since 2.1.3 (replacing the existing constructor without param compressionLevel) */ public PRStream(PdfReader reader, byte[] conts, int compressionLevel) { this.reader = reader; this.offset = -1; if (Document.Compress) { MemoryStream stream = new MemoryStream(); var zip = new ZOutputStream(stream, compressionLevel); zip.Write(conts, 0, conts.Length); zip.Close(); bytes = stream.ToArray(); Put(PdfName.FILTER, PdfName.FLATEDECODE); } else bytes = conts; Length = bytes.Length; }