def decode_stream(stream, stream_def):
    """Apply all specified filters in order to decode stream."""
    s = stream
    if '/Filter' not in stream_def:
        return s
    filters = stream_def['/Filter']
    if type(filters) == str:
        #filters = [filters]
        filters = filters.split()
    if '/DecodeParms' not in stream_def:
        parms = [None] * len(filters)
    else:
        parms = stream_def['/DecodeParms']
        if type(parms) == dict:
            parms = [parms]
    for i, f in enumerate(filters):
        if f == '/FlateDecode':
            try:
                res = zlib.decompress(s)
                if parms[i] and '/Predictor' in parms[i]:
                    predictor = int(parms[i]['/Predictor'])
                    columns = int(parms[i]['/Columns'])
                    res = decode_predictor(res, predictor, columns)
            except:
                return b'#PDFSyntaxException: cannot decode Flate'
        elif f == '/ASCIIHexDecode':
            try:
                res = binascii.unhexlify(s)
            except:
                return b'#PDFSyntaxException: cannot decode ASCIIHex'
        elif f == '/ASCII85Decode':
            try:
                res = base64.a85decode(s, adobe=True)
            except:
                return b'#PDFSyntaxException: cannot decode ASCII85'
        else:
            return b'#PDFSyntaxException: unsupported filter'
    return res
Apply all specified filters in order to decode stream.
pdfsyntax/filters.py