Beispiel #1
0
 public static void Decode(IBuffer buffer, PdfDataObject filter, PdfDirectObject parameters)
 {
     if (filter is PdfName) // Single filter.
     {
         buffer.Decode(Filter.Get((PdfName)filter), (PdfDictionary)parameters);
     }
     else // Multiple filters.
     {
         IEnumerator <PdfDirectObject> filterIterator     = ((PdfArray)filter).GetEnumerator();
         IEnumerator <PdfDirectObject> parametersIterator = (parameters != null ? ((PdfArray)parameters).GetEnumerator() : null);
         while (filterIterator.MoveNext())
         {
             PdfDictionary filterParameters;
             if (parametersIterator == null)
             {
                 filterParameters = null;
             }
             else
             {
                 parametersIterator.MoveNext();
                 filterParameters = (PdfDictionary)Resolve(parametersIterator.Current);
             }
             buffer.Decode(Filter.Get((PdfName)Resolve(filterIterator.Current)), filterParameters);
         }
     }
 }
Beispiel #2
0
 /**
  * <summary>Gets the stream body.</summary>
  * <param name="decode">Defines whether the body has to be decoded.</param>
  */
 public IBuffer GetBody(
     bool decode
     )
 {
     if (!bodyResolved)
     {
         /*
          * NOTE: In case of stream data from external file, a copy to the local buffer has to be done.
          */
         FileSpecification dataFile = DataFile;
         if (dataFile != null)
         {
             Updateable = false;
             body.SetLength(0);
             body.Write(dataFile.GetInputStream());
             body.Dirty = false;
             Updateable = true;
         }
         bodyResolved = true;
     }
     if (decode)
     {
         PdfDataObject filter = Filter;
         if (filter != null) // Stream encoded.
         {
             header.Updateable = false;
             PdfDataObject parameters = Parameters;
             if (filter is PdfName) // Single filter.
             {
                 body.Decode(
                     bytes.filters.Filter.Get((PdfName)filter),
                     (PdfDictionary)parameters
                     );
             }
             else // Multiple filters.
             {
                 IEnumerator <PdfDirectObject> filterIterator     = ((PdfArray)filter).GetEnumerator();
                 IEnumerator <PdfDirectObject> parametersIterator = (parameters != null ? ((PdfArray)parameters).GetEnumerator() : null);
                 while (filterIterator.MoveNext())
                 {
                     PdfDictionary filterParameters;
                     if (parametersIterator == null)
                     {
                         filterParameters = null;
                     }
                     else
                     {
                         parametersIterator.MoveNext();
                         filterParameters = (PdfDictionary)Resolve(parametersIterator.Current);
                     }
                     body.Decode(bytes.filters.Filter.Get((PdfName)Resolve(filterIterator.Current)), filterParameters);
                 }
             }
             Filter            = null; // The stream is free from encodings.
             header.Updateable = true;
         }
     }
     return(body);
 }
Beispiel #3
0
        /**
         * <summary>Gets the stream body.</summary>
         * <param name="decode">Defines whether the body has to be decoded.</param>
         */
        public IBuffer GetBody(
            bool decode
            )
        {
            if (decode)
            {
                // Get 'Filter' entry!

                /*
                 * NOTE: It defines possible encodings applied to the stream.
                 */
                PdfDirectObject filterObj = header[PdfName.Filter];
                if (filterObj != null) // Stream encoded.
                {
                    /*
                     * NOTE: If the stream is encoded, we must decode it before continuing.
                     */
                    PdfDataObject filterDataObj = files.File.Resolve(filterObj);
                    PdfDataObject decodeParms   = header.Resolve(PdfName.DecodeParms);
                    if (filterDataObj is PdfName) // PdfName.
                    {
                        PdfDictionary filterDecodeParms = (PdfDictionary)decodeParms;
                        body.Decode(Filter.Get((PdfName)filterDataObj), filterDecodeParms);
                    }
                    else // MUST be PdfArray.
                    {
                        IEnumerator <PdfDirectObject> filterObjIterator   = ((PdfArray)filterDataObj).GetEnumerator();
                        IEnumerator <PdfDirectObject> decodeParmsIterator = (decodeParms != null ? ((PdfArray)decodeParms).GetEnumerator() : null);
                        while (filterObjIterator.MoveNext())
                        {
                            PdfDictionary filterDecodeParms;
                            if (decodeParmsIterator == null)
                            {
                                filterDecodeParms = null;
                            }
                            else
                            {
                                decodeParmsIterator.MoveNext();
                                filterDecodeParms = (PdfDictionary)files.File.Resolve(decodeParmsIterator.Current);
                            }
                            body.Decode(Filter.Get((PdfName)files.File.Resolve(filterObjIterator.Current)), filterDecodeParms);
                        }
                    }
                    // Update 'Filter' entry!
                    header[PdfName.Filter] = null; // The stream is free from encodings.
                }
            }
            return(body);
        }