summaryrefslogtreecommitdiff
path: root/pdfrw/compress.py
diff options
context:
space:
mode:
authorMatthias Klose <doko@debian.org>2014-07-13 17:50:59 +0200
committerMatthias Klose <doko@debian.org>2014-07-13 17:50:59 +0200
commita1959ba9c0c9f3881c3e593e5aef1046750880f2 (patch)
treee4fc630e9e26b227d9a7e41db65d80f6158e8ae9 /pdfrw/compress.py
pdfrw (0.1-3) unstable; urgency=medium
* QA upload. * Build using dh_python2 # imported from the archive
Diffstat (limited to 'pdfrw/compress.py')
-rw-r--r--pdfrw/compress.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/pdfrw/compress.py b/pdfrw/compress.py
new file mode 100644
index 0000000..e2b16c5
--- /dev/null
+++ b/pdfrw/compress.py
@@ -0,0 +1,26 @@
+# A part of pdfrw (pdfrw.googlecode.com)
+# Copyright (C) 2006-2009 Patrick Maupin, Austin, Texas
+# MIT license -- See LICENSE.txt for details
+
+'''
+Currently, this sad little file only knows how to decompress
+using the flate (zlib) algorithm. Maybe more later, but it's
+not a priority for me...
+'''
+import zlib
+from pdfrw.objects import PdfDict, PdfName
+from pdfrw.errors import log
+from pdfrw.uncompress import streamobjects
+
+def compress(mylist):
+ flate = PdfName.FlateDecode
+ for obj in streamobjects(mylist):
+ ftype = obj.Filter
+ if ftype is not None:
+ continue
+ oldstr = obj.stream
+ newstr = zlib.compress(oldstr)
+ if len(newstr) < len(oldstr) + 30:
+ obj.stream = newstr
+ obj.Filter = flate
+ obj.DecodeParms = None