iTextSharp.text.pdf.PdfStream.FlateCompress C# (CSharp) Метод

FlateCompress() публичный Метод

public FlateCompress ( int compressionLevel ) : void
compressionLevel int
Результат void
        public void FlateCompress(int compressionLevel)
        {
            if (!Document.Compress)
                return;
            // check if the flateCompress-method has already been used
            if (compressed) {
                return;
            }
            this.compressionLevel = compressionLevel;
            if (inputStream != null) {
                compressed = true;
                return;
            }
            // check if a filter already 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(MessageLocalization.GetComposedMessage("stream.could.not.be.compressed.filter.is.not.a.name.or.array"));
                }
            }
            // compress
            MemoryStream stream = new MemoryStream();
            ZDeflaterOutputStream zip = new ZDeflaterOutputStream(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;
        }

Same methods

PdfStream::FlateCompress ( ) : void

Usage Example

Пример #1
0
 /**
 * Gets the stream representing this object.
 *
 * @param   compressionLevel    the compressionLevel
 * @return the stream representing this template
 * @since   2.1.3   (replacing the method without param compressionLevel)
 * @throws IOException
 */
 override public PdfStream GetFormXObject(int compressionLevel) {
     PdfStream s = new PdfStream(content.ToByteArray());
     s.Put(PdfName.TYPE, PdfName.XOBJECT);
     s.Put(PdfName.SUBTYPE, PdfName.PS);
     s.FlateCompress(compressionLevel);
     return s;
 }
All Usage Examples Of iTextSharp.text.pdf.PdfStream::FlateCompress