Coverage for pdfrw/pdfrw/compress.py: 31%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# A part of pdfrw (https://github.com/pmaupin/pdfrw)
2# Copyright (C) 2006-2015 Patrick Maupin, Austin, Texas
3# MIT license -- See LICENSE.txt for details
5'''
6Currently, this sad little file only knows how to compress
7using the flate (zlib) algorithm. Maybe more later, but it's
8not a priority for me...
9'''
11from .objects import PdfName
12from .uncompress import streamobjects
13from .py23_diffs import zlib, convert_load, convert_store
16def compress(mylist):
17 flate = PdfName.FlateDecode
18 for obj in streamobjects(mylist):
19 ftype = obj.Filter
20 if ftype is not None:
21 continue
22 oldstr = obj.stream
23 newstr = convert_load(zlib.compress(convert_store(oldstr)))
24 if len(newstr) < len(oldstr) + 30:
25 obj.stream = newstr
26 obj.Filter = flate
27 obj.DecodeParms = None