#! /usr/bin/perl
#  stampit
#     _                        _ _   
# ___| |_ __ _ _ __ ___  _ __ (_) |_ 
#/ __| __/ _` | '_ ` _ \| '_ \| | __|
#\__ \ || (_| | | | | | | |_) | | |_ 
#|___/\__\__,_|_| |_| |_| .__/|_|\__|
#                       |_|          
# F.P. Laussy -- fabrice.laussy@gmail.com
# Mon Jan 18 19:21:35 GMT 2010
#
# v0.1 -- http://laussy.org/wiki/stampit
#
# Stamp pdf files with their name

@files = <*-poster.pdf>;

foreach $file (@files) {
    $stamp = "newstamp.svg";

    open(oldstamp, "stamp.svg");
    open(newstamp, ">$stamp");

    # change the svg to read name of file
    while ($line = <oldstamp>) {
	$line =~ s/xxx-poster.pdf/$file/;
	print newstamp $line;
    }

    close(oldstamp);
    close(newstamp);

    # create the stamp as pdf
    system("inkscape -A newstamp.pdf newstamp.svg");

    # apply the stamp
    system("pdftk $file background newstamp.pdf output stamped/$file");
}
