def watermark_process():
    """Apply a watermark to a PDF file."""
    # Redirect to watermark page that contains form
    if not request.method == 'POST':
        abort(403)

    # Check if the post request has the file part
    if 'pdf' not in request.files:
        abort(403)

    # Retrieve PDF file and parameters
    file = request.files['pdf']

    # If user does not select file, browser also submit an empty part without filename
    if file.filename == '':
        abort(403)

    # Check if the file is an allowed file type
    if not allowed_file(file.filename):
        abort(403)

    params = {
        'address': request.form['address'],
        'town': request.form['town'],
        'state': request.form['state'],
    }

    # Save file to uploads folder
    filename = secure_filename(file.filename)
    file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

    # Make uploads directory if it does not exist
    if not os.path.exists(app.config['UPLOAD_FOLDER']):
        os.mkdir(app.config['UPLOAD_FOLDER'])

    file.save(file_path)

    # Create new watermarked file and return file path
    watermarked = apply_watermark(file_path, params)
    return send_from_directory(app.config['UPLOAD_FOLDER'], os.path.basename(watermarked))
Apply a watermark to a PDF file.