From 27f637f39ff051a1c8800ab57b74320cb47c6d18 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 2 Nov 2016 10:48:55 +0100 Subject: [PATCH] New script to remove a watermark from a pdf. --- remove_pdf_watermark.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 remove_pdf_watermark.sh diff --git a/remove_pdf_watermark.sh b/remove_pdf_watermark.sh new file mode 100755 index 0000000..48fd379 --- /dev/null +++ b/remove_pdf_watermark.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +WATER_PDF_FILE="${1}" +OLD_WATER="${2}" + +if [ -z "${3}" ]; then + NEW_WATER="" +else + NEW_WATER="${3}" +fi + + +if [ -f "${WATER_PDF_FILE}" ]; then + printf '%s\n' "Replace '${OLD_WATER}' with '${NEW_WATER}' for the PDF file : ${WATER_PDF_FILE}" + + BASE_DIR=$(dirname ${WATER_PDF_FILE}) + BASE_NAME=$(basename ${WATER_PDF_FILE}) + UNCOMPRESS_PDF_FILE="${BASE_DIR}/uncompress_${BASE_NAME}" + UNWATER_PDF_FILE="${BASE_DIR}/unwater_${BASE_NAME}" + + command pdftk "${WATER_PDF_FILE}" output "${UNCOMPRESS_PDF_FILE}" uncompress + + sed -e "s/${OLD_WATER}/${NEW_WATER}/g" "${UNCOMPRESS_PDF_FILE}" >"${UNWATER_PDF_FILE}" + #sed -e "s/UNIVERSITE DE RENNES 1/TEST/g" <"${WATER_PDF_FILE}" >"${UNWATER_PDF_FILE}" + + command pdftk "${UNWATER_PDF_FILE}" output "${WATER_PDF_FILE}" compress + + exit 0 +else + printf '%s\n' "Error with the first arg : ${1}" + exit 1 +fi +