>>> import zlib
>>> with open('path/to/file.pdf', 'rb') as f:
... dat = f.read()
...
>>> almost_from = dat.index(b'stream')
>>> to = dat.index(b'endstream')
>>> print(zlib.decompress(dat[almost_from+7:to]).decode('utf8')) # +8 if it's a windows-born file with carriage returns