Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101282325
pdf-add-blanks
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Feb 7, 11:17
Size
1 KB
Mime Type
text/x-shellscript
Expires
Sun, Feb 9, 11:17 (2 d)
Engine
blob
Format
Raw Data
Handle
24127312
Attached To
R1066 amc-cape
pdf-add-blanks
View Options
#!/bin/bash
function usage() {
if [ $# -gt 0 ]; then
echo "Error: $@"
fi
echo "USAGE: $(basename $0) source.pdf [destination.pdf]"
}
# Sanity checks
for com in $(echo "ps2pdf pdftk pdfinfo"); do
command -v $com > /dev/null
if [ $? -eq 1 ]; then
usage "Command \"$com\" not found. Please, make sure the command is available."
exit
fi
done
TMP_DIR='/tmp'
if [ $# -lt 1 ]
then
usage "No arguments provided."
exit 1
else
INPUT=$1
OUTPUT=$2
if [ -z $2 ]; then
OUTPUT=$1
fi
TMP_OUTPUT=$TMP_DIR/$$_tmp
BLANK=$TMP_DIR/$$_blank
if [ ! -r $INPUT ]; then
usage "File not found: $INPUT"
exit 1
fi
NUM=$(pdftk $1 dump_data | grep 'NumberOfPages' | awk '{split($0,a,": "); print a[2]}')
if [ -z "$NUM" ]; then
usage "Number of pages not detected :-("
exit 1
fi
PAPER_SIZE=$(pdfinfo $INPUT | grep '^Page size:' | cut -d ':' -f 2- | cut -d '(' -f 2 | cut -d ')' -f 1 | tr '[A-Z]' '[a-z]')
if [ -z "$PAPER_SIZE" ]; then
echo "Defaulting to A4 paper size..."
PAPER_SIZE="a4"
fi
COMMSTR=''
for i in $(eval echo {1..$NUM}); do
COMMSTR="$COMMSTR A$i B1"
done
echo "" | ps2pdf -sPAPERSIZE=$PAPER_SIZE - $BLANK
pdftk A=$INPUT B=$BLANK cat $COMMSTR output $TMP_OUTPUT
mv $TMP_OUTPUT $OUTPUT
rm -f $TMP_DIR/$$_*
fi
# RIP
exit 0
Event Timeline
Log In to Comment