#!/bin/bash

if [ $# -lt 1 ]; then
	echo "$(basename $0) PDF [PDF [...]]"
	echo "removes password and restrictions on PDF file"
	which qpdf || echo "you need to install 'qpdf' to make it working."
	exit 1
fi

while [ $# -gt 0 ]; do
	if [ -f "$1" ]; then
		if [ $(qpdf --show-encryption --password='' "$1"|wc -l) -gt 1 ]; then
			qpdf --password='' --decrypt --remove-restrictions --replace-input "$1"
			echo "$1"
		fi
	fi
	shift
done





