diff options
author | zoe | 2018-06-19 11:10:16 +0200 |
---|---|---|
committer | zoe | 2018-06-19 11:10:16 +0200 |
commit | e3544e0859e2f901ab4326603246102a75da829b (patch) | |
tree | ebeab04c511b1c92db311085adfd22dbdf7339ac | |
parent | b1e7e4065a02844e2e8196112fa93b15a76f0215 (diff) | |
download | aur-e3544e0859e2f901ab4326603246102a75da829b.tar.gz |
Add interval pages option
-rw-r--r-- | .SRCINFO | 7 | ||||
-rw-r--r-- | PKGBUILD | 8 | ||||
-rwxr-xr-x | pdf-remove-blank-pages.sh | 44 |
3 files changed, 46 insertions, 13 deletions
@@ -1,8 +1,8 @@ # Generated by mksrcinfo v8 -# Mon Jun 18 23:18:24 UTC 2018 +# Tue Jun 19 09:09:41 UTC 2018 pkgbase = pdf-remove-blank-pages pkgdesc = Automatically remove blank pages from pdf. For text-pdf only, not for images-pdf (removes pages with no text in it) - pkgver = 0.1 + pkgver = 0.2 pkgrel = 1 url = https://repolinux.wordpress.com/2012/04/05/automatically-remove-blank-pages-from-pdf/ arch = any @@ -11,10 +11,11 @@ pkgbase = pdf-remove-blank-pages depends = bash depends = pdftk depends = poppler + depends = gawk source = non-blank-page-ranges.py source = pdf-remove-blank-pages.sh md5sums = 1a9c76689a828c18b1263ef11c3ee990 - md5sums = b461a834fc260404862e202b154c474e + md5sums = e368efb443e71690e7319ed05bef21d9 pkgname = pdf-remove-blank-pages @@ -1,15 +1,15 @@ # Maintainer: zoe <chp321 AT gmail DOT com> pkgname=pdf-remove-blank-pages -pkgver=0.1 +pkgver=0.2 pkgrel=1 pkgdesc="Automatically remove blank pages from pdf. For text-pdf only, not for images-pdf (removes pages with no text in it)" arch=(any) url="https://repolinux.wordpress.com/2012/04/05/automatically-remove-blank-pages-from-pdf/" license=("GPLv3+") -depends=('python' 'bash' 'pdftk' 'poppler') +depends=('python' 'bash' 'pdftk' 'poppler' 'gawk') source=("non-blank-page-ranges.py" "pdf-remove-blank-pages.sh") -md5sums=('1a9c76689a828c18b1263ef11c3ee990' 'b461a834fc260404862e202b154c474e') +md5sums=('1a9c76689a828c18b1263ef11c3ee990' 'e368efb443e71690e7319ed05bef21d9') package() { @@ -17,5 +17,5 @@ package() { install -D -m 0755 $srcdir/non-blank-page-ranges.py \ $pkgdir/usr/bin/non-blank-page-ranges.py install -D -m 0755 $srcdir/${pkgname}.sh \ - $pkgdir/usr/bin/${pkgname}.sh + $pkgdir/usr/bin/${pkgname} } diff --git a/pdf-remove-blank-pages.sh b/pdf-remove-blank-pages.sh index f06f408ed472..5de0f84cd962 100755 --- a/pdf-remove-blank-pages.sh +++ b/pdf-remove-blank-pages.sh @@ -1,28 +1,60 @@ #! /bin/bash -for filename in "$@"; do +echo $@ +BEGIN=1 +END=0 +filename="" + +while getopts b:f:e:h option +do + case "${option}" in + b) BEGIN=${OPTARG};; + f) filename=${OPTARG};; + e) END=${OPTARG};; + h) echo "Usage: pdf-remove-blank-pages [-b <FIRST_PAGE>] [-e <LAST_PAGE>] -f <PDF-file>" + echo " [FIRST_PAGE LAST_PAGE] = pages-interval where to remove blank pages ; default is 1-End" + echo " pdf-remove-blank-pages -h : displays that help and exit" + exit;; + *) echo "invalid parameter" + echo " " + echo "Usage: pdf-remove-blank-pages [-b <FIRST_PAGE>] [-e <LAST_PAGE>] -f <PDF-file>" + echo " [FIRST_PAGE LAST_PAGE] = pages-interval where to remove blank pages ; default is 1-End" + echo " pdf-remove-blank-pages -h : displays that help and exit" + exit;; + esac +done + +if [ $filename == "" ]; then + echo "-f <PDF-file> is missing ; aborted" + exit 99 +fi + +if [ $END == 0 ]; then + END=$(pdfinfo $filename | grep Pages | awk '{print $2}') +fi + +echo "BEGIN="$BEGIN +echo "END="$END +echo "filename="$filename + # get non-blank ranges - ranges="$(pdftotext "$filename" - | \ + ranges="$(pdftotext -f $BEGIN -l $END "$filename" - | \ "/usr/bin/non-blank-page-ranges.py")" if [ -z "$ranges" ]; then echo "no non-blank pages found in $filename" >&2 - continue fi # rename pdf if [ -e "${filename}.old.pdf" ]; then echo "file exists: ${filename}.old.pdf" >&2 - continue fi mv -n "$filename" "${filename}.old.pdf" if [ -e "$filename" -o ! -e "${filename}.old.pdf" ]; then echo "couldn't rename file $filename" >&2 - continue fi # create new pdf with non-blank pages only pdftk "${filename}.old.pdf" cat $ranges output "$filename" -done |