Example #1
0
 def _extend(self, obj):
     stream = getattr(obj, "stream", None)
     if stream is not None:
         # stream = stream.encode("utf-16be")
         d = {"__streamdata__": stream, "/Length": len(stream)}
         d.update(obj)
         dct = pdf.StreamObject.initializeFromDictionary(d)
         if "/Filter" in obj and obj["/Filter"] == "/FlatDecode":
             del dct["/Filter"]
             dct = dct.flateEncode()
     else:
         dct = pdf.DictionaryObject()
     for k, v in obj.items():
         if isinstance(v, pdf.DictionaryObject):
             if v.indirect:
                 v = self._extend(v)
                 v = self._addObject(v)
             else:
                 v = self._extend(v)
         elif isinstance(v, list):
             result = pdf.ArrayObject()
             for va in v:
                 if isinstance(va, pdf.DictionaryObject):
                     if va.indirect:
                         va = self._extend(va)
                         va = self._addObject(va)
                     else:
                         va = self._extend(va)
                 result.append(va)
             v = result
         dct[k] = v
     return dct
Example #2
0
 def _extend(self, obj):
     stream = getattr(obj, "stream", None)
     if stream is not None:
         d = {"__streamdata__": stream, "/Length": len(stream)}
         d.update(obj)
         dct = pdf.StreamObject.initializeFromDictionary(d)
     else:
         dct = pdf.DictionaryObject()
     for k, v in obj.items():
         if isinstance(v, pdf.DictionaryObject):
             if v.indirect:
                 v = self._extend(v)
                 v = self._addObject(v)
             else:
                 v = self._extend(v)
         elif isinstance(v, list):
             v = pdf.ArrayObject(v)
         dct[k] = v
     return dct