Skip to content

Commit

Permalink
Allowing input file to be same as output file.
Browse files Browse the repository at this point in the history
  • Loading branch information
chazeon committed Dec 15, 2023
1 parent e90bf81 commit 83901d6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def removeWatermark(input_fname: str, output_fname: str):

with open(input_fname, "rb") as input_file, open(output_fname, "wb") as output_file:
with open(input_fname, "rb") as input_file:

reader = PdfReader(input_file)
writer = PdfWriter()
Expand All @@ -14,14 +14,18 @@ def removeWatermark(input_fname: str, output_fname: str):

writer.add_page(page)

with open(output_fname, "wb") as output_file:

writer.write(output_file)

if __name__ == "__main__":

import sys

if len(sys.argv) != 3:
raise RuntimeError("Arguments not correct!")

removeWatermark(sys.argv[1], sys.argv[2])
if len(sys.argv) == 2:
removeWatermark(sys.argv[1], sys.argv[1])
elif len(sys.argv) == 3:
removeWatermark(sys.argv[1], sys.argv[2])
else:
raise RuntimeError("Wrong number of arguments!")

0 comments on commit 83901d6

Please sign in to comment.