#!/bin/bash # File created on 19/06/09 # Author: Mariano Rodriguez-Muro #################### # DEFAULT VALUES #################### PAGES=- NUP=1x2 SCALE=1.25 DELTA="0cm -6.5cm" OFFSET="0cm 0cm" LANDSCAPE=true VERBOSE=false FILE=main.pdf OPEN=true ############################## # PROCESSING INPUT PARAMETERS ############################## while getopts ":d:o:p:n:hvf:O" optname do case "$optname" in "d") DELTA=$OPTARG ;; "o") OFFSET=$OPTARG ;; "p") PAGES=$OPTARG ;; "n") NUP=$OPTARG ;; "s") SCALE=$OPTARG ;; "h") LANDSCAPE=false ;; "f") FILE=$OPTARG ;; "v") VERBOSE=true ;; "O") OPEN=false ;; "?") echo Usage: echo echo " lncs2side [OPTIONS]" echo echo Where [OPTIONS] is one or more of the following optional parameters echo echo " -f FILE sets the input file to be FILE. " echo " Defaults to main.pdf, e.g., -f some.pdf " echo " -v sets verbose mode ON. Defaults to OFF" echo " -O opens the created PDF file when the script finishes. " echo " Defaults to TRUE." echo " -o OFFSET sets the OFFSET of the pages. Defaults to 0cm 0cm." echo " -d DELTA sets DELTA for the pages. Defaults to \"0cm -6.5cm\"" echo " -p PAGES sets the PAGES parameter. Defaults to \"-\"" echo " -n NUP sets the NUP parameter. Defaults to \"1x2\"" echo " -s SCALE set the SCALE parameter. Defaults to 1.25" echo " -h sets LANSCAPE to false. Default is true." echo echo " For a full description of the parameters consult the latex \"pdfpages\" package documentation at http://dods.ipsl.jussieu.fr/fast/documents/pdfpages.pdf" echo exit -1 ;; ":") echo "No argument value for option $OPTARG" ;; *) # Should not occur echo "Unknown error while processing options" ;; esac done echo echo Using pages=$PAGES,nup=$NUP,scale=$SCALE echo " delta=$DELTA,offset=$OFFSET,landscape=$LANDSCAPE" echo echo Input file=$FILE #################### # PREPARING TEMP FILE NAMES #################### SIZE=${#FILE} END=$(($SIZE-4)) FILENAME=${FILE:0:END} EXTENSION=${FILE:$((END+1))} if [ ! -f "$FILE" ] then echo ERROR: input file doesn\'t exists, aborting... exit -1 fi if [ $EXTENSION != 'pdf' ] then echo echo The input file must be a pdf file echo exit -1 fi # TEMP FILE SUFIX TEMP_BASE=$FILENAME"_lncs2page" TEMP_FILE=$TEMP_BASE".tex" if [ -e "$TEMP_FILE" ] then rm $TEMP_FILE fi #################### # PROCESSING TEX #################### echo '\documentclass[a4paper]{article}' >> $TEMP_FILE echo '\usepackage{pdfpages}' >> $TEMP_FILE echo '\begin{document}' >> $TEMP_FILE echo '\includepdf[pages='$PAGES',landscape='$LANDSCAPE',scale='$SCALE',delta='$DELTA',nup='$NUP']{'$FILE'}' >> $TEMP_FILE echo '\end{document}' >> $TEMP_FILE echo '\endinput' >> $TEMP_FILE if [ $VERBOSE = 'true' ] then pdflatex $TEMP_FILE else pdflatex $TEMP_FILE > /dev/null fi if [ -e "$TEMP_FILE" ] then rm $TEMP_BASE.aux $TEMP_BASE.log $TEMP_FILE fi # DONE echo 'Job done! Enjoy reading in double page without killing your eyes!' echo if [ $OPEN = 'true' ] then open $TEMP_BASE".pdf" fi