예제 #1
0
파일: generic.py 프로젝트: USGM/PyPDF2
 def writeToStream(self, stream, encryption_key):
     # Try to write the string out as a PDFDocEncoding encoded string.  It's
     # nicer to look at in the PDF file.  Sadly, we take a performance hit
     # here for trying...
     try:
         bytearr = encode_pdfdocencoding(self)
     except UnicodeEncodeError:
         bytearr = codecs.BOM_UTF16_BE + self.encode("utf-16be")
     if encryption_key:
         bytearr = RC4_encrypt(encryption_key, bytearr)
         obj = ByteStringObject(bytearr)
         obj.writeToStream(stream, None)
     else:
         stream.write(b_("("))
         for c in bytearr:
             if not chr_(c).isalnum() and c != b_(' '):
                 stream.write(b_("\\%03o" % ord_(c)))
             else:
                 stream.write(b_(chr_(c)))
         stream.write(b_(")"))
예제 #2
0
 def writeToStream(self, stream, encryption_key):
     # Try to write the string out as a PDFDocEncoding encoded string.  It's
     # nicer to look at in the PDF file.  Sadly, we take a performance hit
     # here for trying...
     try:
         bytearr = encode_pdfdocencoding(self)
     except UnicodeEncodeError:
         bytearr = codecs.BOM_UTF16_BE + self.encode("utf-16be")
     if encryption_key:
         bytearr = RC4_encrypt(encryption_key, bytearr)
         obj = ByteStringObject(bytearr)
         obj.writeToStream(stream, None)
     else:
         stream.write(b_("("))
         for c in bytearr:
             if not chr_(c).isalnum() and c != b_(' '):
                 stream.write(b_("\\%03o" % ord_(c)))
             else:
                 stream.write(b_(chr_(c)))
         stream.write(b_(")"))