Commit 2865ea54 authored by Giuseppe Lombardi's avatar Giuseppe Lombardi

Add new file

parents
#!/bin/bash
# Imposition of a PDF document to generate a booklet
# target format is selectable (A5, A4, ...)
# default format is A4
#
# Depends on packages
# * pdfjam
# * poppler-utils
#
# Parameter :
# nothing (anymore)
#
# Version history :
# 26/09/2012, V1.0 - Creation by N. Bernaerts
# 05/05/2014, V2.0 - Add target format selection (thanks to Robin idea)
# 2015 - Added Zenity eyecandy, and pages selection by Fernando Virdia
FILE=`zenity --file-selection --title="Select a File"`
case $? in
0)
echo "\"$FILE\" selected."
;;
1)
echo "No file selected."
exit
;;
-1)
echo "An unexpected error has occurred."
exit
;;
esac
# suffix to be added at the end of booklet file
DOC_SUFFIX="book"
SPL_SUFFIX="splitted"
# determine file names
DOC_ORIGINAL="$FILE"
DOC_SPLITTED=$(echo "$FILE" | sed 's/\(.*\)\..*/\1/')-$SPL_SUFFIX.pdf
DOC_BOOKLET=$(echo "$FILE" | sed 's/\(.*\)\..*/\1/')-$DOC_SUFFIX.pdf
# select pages
PAGES=`zenity --entry --text "Pagine da stampare (lascia vuoto per tutte le pagine)"`
# select target format
ARR_FORMAT=('false' 'A2' 'false' 'A3' 'true' 'A4' 'false' 'A5' 'false' 'Letter' 'false' 'Executive' 'false' 'Legal')
TITLE=`basename "$FILE"`
TEXT="Booklet will be generated from this document.\nPlease select target format.\n"
FORMAT=`zenity --list --radiolist --width 350 --height 380 --title "$TITLE" --text "$TEXT" --column="Choice" --column="Format" ${ARR_FORMAT[@]}`
# if a format has been selected
if [ "$FORMAT" != "" ]
then
# determine number of pages of original PDF
NUM_PAGES_ORIG=`pdfinfo "$DOC_ORIGINAL" | grep Pages | sed 's/^Pages:[ ]*\([0-9]*\).*$/\1/g'`
if [ "$PAGES" == "" ]
then
PAGES="1-"
fi
# split file
pdfjam "$DOC_ORIGINAL" $PAGES --outfile "$DOC_SPLITTED"
# set target format as expected by pdfbook
FORMAT_OPTION="--${FORMAT,,}paper"
# determine number of pages of original PDF
NUM_PAGES=`pdfinfo "$DOC_SPLITTED" | grep Pages | sed 's/^Pages:[ ]*\([0-9]*\).*$/\1/g'`
# determine if there is a need to add blank pages at the end
DIV_RESULT=`expr $NUM_PAGES % 4`
if [ $DIV_RESULT -gt 0 ]
then
# add pages to get multiple of 4
NUM_PAGES=`expr $NUM_PAGES + 4 - $DIV_RESULT`
fi
# generate document with proper page number (multiple of 4)
zenity --info --text="Costruzione iniziata. Potrebbe metterci un po'. Chiudi questa finestra."
pdfbook $FORMAT_OPTION --signature $NUM_PAGES --booklet true --landscape "$DOC_SPLITTED" -o "$DOC_BOOKLET"
rm -rf "$DOC_SPLITTED"
zenity --info --text="Libretto completato. Nuovo file: $DOC_BOOKLET"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment