Skip to content

Instantly share code, notes, and snippets.

@viveksb007
Created March 22, 2018 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viveksb007/bc395de24823d9a302825b0ed5f77783 to your computer and use it in GitHub Desktop.
Save viveksb007/bc395de24823d9a302825b0ed5f77783 to your computer and use it in GitHub Desktop.
from PyPDF2 import PdfFileReader, PdfFileWriter
DOWNLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__)) + '/downloads/'
app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER
def process_file(path, filename):
remove_watermark(path, filename)
def remove_watermark(path, filename):
input_file = PdfFileReader(open(path, 'rb'))
output = PdfFileWriter()
for page_number in range(input_file.getNumPages()):
page = input_file.getPage(page_number)
page.mediaBox.lowerLeft = (page.mediaBox.getLowerLeft_x(), 20)
output.addPage(page)
output_stream = open(app.config['DOWNLOAD_FOLDER'] + filename, 'wb')
output.write(output_stream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment