Example #1
0
        protected internal virtual void UpdateCompressionFilter(PdfStream pdfStream)
        {
            PdfObject filter = pdfStream.Get(PdfName.Filter);

            if (filter == null)
            {
                pdfStream.Put(PdfName.Filter, PdfName.FlateDecode);
            }
            else
            {
                PdfArray filters = new PdfArray();
                filters.Add(PdfName.FlateDecode);
                if (filter is PdfArray)
                {
                    filters.AddAll((PdfArray)filter);
                }
                else
                {
                    filters.Add(filter);
                }
                PdfObject decodeParms = pdfStream.Get(PdfName.DecodeParms);
                if (decodeParms != null)
                {
                    if (decodeParms is PdfDictionary)
                    {
                        PdfArray array = new PdfArray();
                        array.Add(new PdfNull());
                        array.Add(decodeParms);
                        pdfStream.Put(PdfName.DecodeParms, array);
                    }
                    else
                    {
                        if (decodeParms is PdfArray)
                        {
                            ((PdfArray)decodeParms).Add(0, new PdfNull());
                        }
                        else
                        {
                            throw new PdfException(PdfException.DecodeParameterType1IsNotSupported).SetMessageParams(decodeParms.GetType
                                                                                                                         ().ToString());
                        }
                    }
                }
                pdfStream.Put(PdfName.Filter, filters);
            }
        }