diff options
Diffstat (limited to 'lib/pdfrw/pdfcompress.py')
| -rw-r--r-- | lib/pdfrw/pdfcompress.py | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/lib/pdfrw/pdfcompress.py b/lib/pdfrw/pdfcompress.py deleted file mode 100644 index 1c11970..0000000 --- a/lib/pdfrw/pdfcompress.py +++ /dev/null | |||
| @@ -1,57 +0,0 @@ | |||
| 1 | # A part of pdfrw (pdfrw.googlecode.com) | ||
| 2 | # Copyright (C) 2006-2009 Patrick Maupin, Austin, Texas | ||
| 3 | # MIT license -- See LICENSE.txt for details | ||
| 4 | |||
| 5 | ''' | ||
| 6 | Currently, this sad little file only knows how to decompress | ||
| 7 | using the flate (zlib) algorithm. Maybe more later, but it's | ||
| 8 | not a priority for me... | ||
| 9 | ''' | ||
| 10 | |||
| 11 | from __future__ import generators | ||
| 12 | |||
| 13 | try: | ||
| 14 | set | ||
| 15 | except NameError: | ||
| 16 | from sets import Set as set | ||
| 17 | |||
| 18 | import zlib | ||
| 19 | from pdfobjects import PdfDict, PdfName | ||
| 20 | |||
| 21 | |||
| 22 | def streamobjects(mylist): | ||
| 23 | for obj in mylist: | ||
| 24 | if isinstance(obj, PdfDict) and obj.stream is not None: | ||
| 25 | yield obj | ||
| 26 | |||
| 27 | def uncompress(mylist, warnings=set()): | ||
| 28 | flate = PdfName.FlateDecode | ||
| 29 | for obj in streamobjects(mylist): | ||
| 30 | ftype = obj.Filter | ||
| 31 | if ftype is None: | ||
| 32 | continue | ||
| 33 | if isinstance(ftype, list) and len(ftype) == 1: | ||
| 34 | # todo: multiple filters | ||
| 35 | ftype = ftype[0] | ||
| 36 | parms = obj.DecodeParms | ||
| 37 | if ftype != flate or parms is not None: | ||
| 38 | msg = 'Not decompressing: cannot use filter %s with parameters %s' % (repr(ftype), repr(parms)) | ||
| 39 | if msg not in warnings: | ||
| 40 | warnings.add(msg) | ||
| 41 | print msg | ||
| 42 | else: | ||
| 43 | obj.stream = zlib.decompress(obj.stream) | ||
| 44 | obj.Filter = None | ||
| 45 | |||
| 46 | def compress(mylist): | ||
| 47 | flate = PdfName.FlateDecode | ||
| 48 | for obj in streamobjects(mylist): | ||
| 49 | ftype = obj.Filter | ||
| 50 | if ftype is not None: | ||
| 51 | continue | ||
| 52 | oldstr = obj.stream | ||
| 53 | newstr = zlib.compress(oldstr) | ||
| 54 | if len(newstr) < len(oldstr) + 30: | ||
| 55 | obj.stream = newstr | ||
| 56 | obj.Filter = flate | ||
| 57 | obj.DecodeParms = None | ||
