First commit

This commit is contained in:
Gabriel Pérez-Cerezo 2022-10-21 18:07:23 +02:00
commit a5746f4136
2 changed files with 119 additions and 0 deletions

89
fgfiller.sh Normal file
View file

@ -0,0 +1,89 @@
#!/bin/bash
## Copyright (C) 2022 Antonia <antonia@antonia.is>
## fills in personal data on forms generated by travelynx
tmpfile=$(mktemp --tmpdir XXXXX.fdf)
cat - <<EOF >>$tmpfile
%FDF-1.2
1 0 obj<</FDF<< /Fields[
EOF
function write_field() {
echo "<< /T ($1) /V ($2) >>" >> $tmpfile
}
source ~/.fgfillerrc
if [ -n "$IBAN" ]; then
write_field S1F29 "Auszahlung oder Überweisung"
if [ -z "$ACCHOLDER" ]; then
ACCHOLDER="$FIRSTNAME $LASTNAME"
fi
write_field S2F20 "$ACCHOLDER"
write_field S2F21 "$IBAN"
write_field S2F22 "$BIC"
else
write_field S1F29 "Gutschein"
fi
write_field S2F1 "$GENDER"
[ -n "$TITLE" ] && write_field S2F2 "$TITLE"
[ -n "$COMPANY" ] && write_field S2F3 "$COMPANY"
write_field S2F4 "$LASTNAME"
write_field S2F5 "$FIRSTNAME"
[ -n "$CO" ] && write_field S2F6 "$CO"
[ -n "$PHONENR" ] && write_field S2F7 "$PHONENR"
write_field S2F8 "$STREET"
write_field S2F9 "$HOUSENR"
[ -n "$COUNTRY" ] && write_field S2F10 "$COUNTRY"
write_field S2F11 "$ZIP"
if [ -n "$CARDNR" ]; then
write_field S2F15 "$CARDNR"
if [ -n "$DOB" ]; then
write_field S2F13 "BahnCard 100-Nr."
k=0
for i in $DOB ; do
write_field S2F$((k+16)) $i
k=$((k+1))
done
else
write_field S2F14 "Zeitkarten-Nr."
fi
fi
cat - <<EOF>>$tmpfile
] >> >>
endobj
trailer
<</Root 1 0 R>>
%%EOF
EOF
mkdir -p output
for k in "$@"; do
outfile="output/$(basename "$k")"
tmp=$(mktemp --tmpdir XXXXX.pdf)
sed "s/Auszahlung#20oder#20#dcberweisung/Auszahlung#20oder#20#c3Sberweisung/g" "$k" > "$tmp" # solve pdftk bug
pdftk "$tmp" fill_form $tmpfile output "$outfile"
rm $tmp
done
rm $tmpfile

30
fgfillerrc.sample Normal file
View file

@ -0,0 +1,30 @@
# Sample fgfillerrc file
# Payment info
# IBAN number. Leave blank if a coupon is desired instead of wire transfer
IBAN=""
# BIC
BIC=""
# Account holder, if separate from the claimant
ACCHOLDER=""
# Personal data
GENDER="" # Must be "Herr" or "Frau"
# Academic title (Optional)
TITLE=""
# Company name (Optional)
COMPANY=""
# First name of the claimant
FIRSTNAME=""
# Last name of the claimant
LASTNAME=""
# Address data of the claimant
STREET=""
HOUSENR=""
CO="" # c/o or similar (optonal)
COUNTRY="" # country code, leave empty if Germany
ZIP="" # Zip code
CARDNR="" # Bahncard 100 or monthly ticket number
DOB="" # Date of birth in case of Bahncard 100, Format DD MM YYYY separated by spaces