Hallo zusammen,
ich möchte ein PDF-Formular mit Hilfe von pdftk und perl ausfüllen. Das nötige Wissen habe ich mir im Netz zusammengeklaubt.
Der Vorgang funktioniert bei mir (Ubuntu-Rechner)so:
pdftk formular.pdf dump_data_fields | field2pl.plx > template.pl
Damit erzeuge ich eine Textdatei, in die ich die Daten eintragen kann.
Ich trage die Daten ein und ich fahre fort mit:
genfdf.plx template.pl > output.fdf
und mit:
pdftk formular.pdf fill_form output.fdf output formular_ausgefuellt.pdf
Das ganze funktioniert auch so weit ganz gut, nur nervt mich, dass ich so vieles doppel eintragen muss und auch keine Additionen durchführen kann.
Wahrscheinlich sind meine Fragen ziemlich dumm, aber ich habe wenig Ahnung von Perl und suche einfach nach einer Lösung für mein Problem. Ich hoffe auf Euer Verständnis.
Hier erstmal die Datei field2pl.plx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use encoding ':locale';
my ($LOOKING,$INSTATE)=(0,1);
my $state=$LOOKING;
while(<>){
if (($state==$LOOKING) && m/---/){
$state=$INSTATE;
}
if (($state==$INSTATE) && m/^FieldName:\s+(.*)$/){
push(@names,$1);
$state=$LOOKING;
}
}
print '$fields={',"\n";
print join(",\n",map {sprintf("'%s'=>q{}",$_);} @names);
print "\n};\n";
Hier die Datei genfdf.plx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;
use utf8;
use PDF::FDF::Simple;
use Getopt::Std;
our $opt_o;
getopts("o:");
my $outfile=$opt_o || "-";
my %content=();
our $fields;
foreach my $file (@ARGV){
open(IN,"$file") || die ("could not open $file");
undef($/);
my $in=<IN>;
eval($in);
die "reading input failed: $@" if $@;
%content=(%content, %$fields);
}
my $f=new PDF::FDF::Simple({
filename => $outfile,
content => \%content });
$f->save;
und die Datei template.pl, stark gekuerzt:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$fields={
'antragsteller.strasse_hausnr'=>q{Holzweg 13},
'antragsteller.postleitzahl'=>q{12345},
'antragsteller.ort'=>q{Sonstwo},
'antragsteller.telefon'=>q{0815/12345},
'antragsteller.emailadresse'=>q{seppmeier@web.de},
'antragsteller.ort_datum'=>q{Sonstwo, den 28.9.2015},
'antragsteller.familienname'=>q{Meier},
'antragsteller.vorname'=>q{Joseph}
'projekt.termin'=>q{11.11.2016, Bürgerhaus Sonstwo},
'firma.name'=>q{Kulturverein Sonstwo},
'iban.zpflicht'=>q{DE123435987},
'bic.nummer'=>q{GENODXYZ},
'ibanbic.info'=>q{GENODXYZ},
'kontoinhaber.name'=>q{Joseph Meier},
'kontoinhaber.strasse_hausnr'=>q{Holzweg 13},
'kontoinhaber.postleitzahl'=>q{12345},
'kontoinhaber.ort'=>q{Sonstwo},
'referat'=>q{Referat für Kultur},
'projekttitel'=>q{Tolles Event},
'datum.projekt'=>q{28.9.2015},
'brutto.hilfe'=>q{Nicht vorsteuerabzugsberechtig: Angabe in Bruttobeträgen},
'aufwendung1'=>q{Honorare},
'ak1'=>int(q{3000}),
'ae1'=>int(q{3000}),
'aufwendung2'=>q{KSK},
'ak2'=>int(q{117}),
'ae2'=>int(q{117}),
'spk1'=>q{2367},
'spe1'=>q{2367},
};
Last edited: 2015-09-28 12:46:23 +0200 (CEST)