/**
         * Generate an object that contains an CMS Compressed Data
         */
        public CmsCompressedData Generate(
            CmsProcessable content,
            string compressionOid)
        {
            AlgorithmIdentifier comAlgId;
            Asn1OctetString     comOcts;

            try
            {
                MemoryStream          bOut = new MemoryStream();
                ZDeflaterOutputStream zOut = new ZDeflaterOutputStream(bOut);

                content.Write(zOut);

                zOut.Close();

                comAlgId = new AlgorithmIdentifier(
                    new DerObjectIdentifier(compressionOid),
                    null);

                comOcts = new BerOctetString(bOut.ToArray());
            }
            catch (IOException e)
            {
                throw new CmsException("exception encoding data.", e);
            }

            ContentInfo comContent  = new ContentInfo(CmsObjectIdentifiers.Data, comOcts);
            ContentInfo contentInfo = new ContentInfo(
                CmsObjectIdentifiers.CompressedData,
                new CompressedData(comAlgId, comContent));

            return(new CmsCompressedData(contentInfo));
        }
Esempio n. 2
0
 public override void Close()
 {
     _out.Close();
     _eiGen.Close();
     _cGen.Close();
     _sGen.Close();
     base.Close();
 }
Esempio n. 3
0
        virtual public void WriteIccProfile(byte[] data)
        {
            MemoryStream stream = new MemoryStream();

            stream.WriteByte((byte)'I');
            stream.WriteByte((byte)'C');
            stream.WriteByte((byte)'C');
            stream.WriteByte(0);
            stream.WriteByte(0);
            ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);

            zip.Write(data, 0, data.Length);
            zip.Close();
            WriteChunk(iCCP, stream.ToArray());
        }
Esempio n. 4
0
 /**
  * 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();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);
         zip.Write(conts, 0, conts.Length);
         zip.Close();
         bytes = stream.ToArray();
         Put(PdfName.FILTER, PdfName.FLATEDECODE);
     }
     else
     {
         bytes = conts;
     }
     Length = bytes.Length;
 }
Esempio n. 5
0
 /**Sets the data associated with the stream
  * @param data raw data, decrypted and uncompressed.
  */
 public void SetData(byte[] data)
 {
     Remove(PdfName.FILTER);
     this.offset = -1;
     if (Document.Compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream);
         zip.Write(data, 0, data.Length);
         zip.Close();
         bytes = stream.ToArray();
         Put(PdfName.FILTER, PdfName.FLATEDECODE);
     }
     else
     {
         bytes = data;
     }
     Length = bytes.Length;
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a new PDF stream object that will replace a stream
 /// in a existing PDF file.
 /// @since   2.1.3 (replacing the existing constructor without param compressionLevel)
 /// </summary>
 /// <param name="reader">the reader that holds the existing PDF</param>
 /// <param name="conts">the new content</param>
 /// <param name="compressionLevel">the compression level for the content</param>
 public PrStream(PdfReader reader, byte[] conts, int compressionLevel)
 {
     this.reader = reader;
     offset      = -1;
     if (Document.Compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);
         zip.Write(conts, 0, conts.Length);
         zip.Close();
         Bytes = stream.ToArray();
         Put(PdfName.Filter, PdfName.Flatedecode);
     }
     else
     {
         Bytes = conts;
     }
     Length = Bytes.Length;
 }
Esempio n. 7
0
 /// <summary>
 /// 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.
 /// @since   iText 2.1.3
 /// </summary>
 /// <param name="data">raw data, decrypted and uncompressed.</param>
 /// <param name="compress">true if you want the stream to be compresssed.</param>
 /// <param name="compressionLevel">a value between -1 and 9 (ignored if compress == false)</param>
 public void SetData(byte[] data, bool compress, int compressionLevel)
 {
     Remove(PdfName.Filter);
     offset = -1;
     if (Document.Compress && compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);
         zip.Write(data, 0, data.Length);
         zip.Close();
         Bytes            = stream.ToArray();
         CompressionLevel = compressionLevel;
         Put(PdfName.Filter, PdfName.Flatedecode);
     }
     else
     {
         Bytes = data;
     }
     Length = Bytes.Length;
 }
Esempio n. 8
0
        virtual public void WriteData(byte[] data, int stride)
        {
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, 5);
            int k;

            for (k = 0; k < data.Length - stride; k += stride)
            {
                zip.WriteByte(0);
                zip.Write(data, k, stride);
            }
            int remaining = data.Length - k;

            if (remaining > 0)
            {
                zip.WriteByte(0);
                zip.Write(data, k, remaining);
            }
            zip.Close();
            WriteChunk(IDAT, stream.ToArray());
        }