Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfneal committed Aug 16, 2018
2 parents 5babaaf + e4ad9d1 commit 010d5b0
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions pdfconduit/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,13 @@ def __init__(self, pdf, user_pw, owner_pw=None, output=None, bit128=True, allow_
self.owner_pw = owner_pw
self.output = add_suffix(pdf, 'secured') if not output else output
self.encrypt_128 = bit128
self.permissions = self._set_permissions(allow_printing, allow_commenting)
self.allow_printing = allow_printing
self.allow_commenting = allow_commenting
self.encrypt()

def __str__(self):
return str(self.output)

@staticmethod
def _set_permissions(allow_printing, allow_commenting):
if allow_printing and not allow_commenting:
return -1852
elif allow_printing and allow_commenting:
return -1500
elif not allow_printing and allow_commenting:
return -800
else:
return 0

def encrypt(self):
# Create PDF writer object
pdf_writer = PdfFileWriter()
Expand All @@ -43,7 +33,7 @@ def encrypt(self):

# Apply encryption to writer object
pdf_writer.encrypt(self.user_pw, self.owner_pw, use_128bit=self.encrypt_128,
restrict_permission=self.permissions)
allow_printing=self.allow_printing, allow_commenting=self.allow_commenting)

pdf_writer.addMetadata({
'/Producer': 'pdfconduit',
Expand Down

0 comments on commit 010d5b0

Please sign in to comment.