#!/usr/bin/perl
########################################################################
# File:           publicfiles/pdfprinter.pl                            #
# myLinux Server: Copyright (c) 2003 Michael Oberg                     #
# Version:        0.93                                                 #
# Author:         Michael Oberg <michael.oberg@fourier-group.de>       #
#                                                                      #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or    #
# (at your option) any later version.                                  #
#                                                                      #
# This program is distributed in the hope that it will be useful,      #
# but WITHOUT ANY WARRANTY; without even the implied warranty of       #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         #
# GNU General Public License for more details.                         #
#                                                                      #
# You should have received a copy of the GNU Public License along      #
# with this package; if not, write to the Free Software Foundation,    #
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.       #
########################################################################

# Path to output directory:
$OUTPUTDIR = "/var/lib/samba/pdfdocs";

if (@ARGV < 1) {
  die ("Usage: pdfprinter.pl <FILENAME>\n");
}

$FILENAME = $ARGV[0];
$TITLE = `grep '%%Title: ' "$FILENAME"`;
print "filename = $FILENAME\n";
$TITLE =~ /^%%Title: ([^\n]*)/s;
print "title = $TITLE\n";
$DOCTITLE = $1;
print "doctitle = $DOCTITLE\n";
$DOCTITLE =~ s/ - /-/g;
$DOCTITLE =~ s/ /_/g;
$DOCTITLE =~ s|http://||g;
$DOCTITLE =~ s|/|_|g;
$DOCTITLE =~ s|:|_|g;
print "outtitle = $DOCTITLE\n";

$DUMMY = `/usr/bin/ps2pdf "$FILENAME" $OUTPUTDIR/$DOCTITLE.pdf`;
$DUMMY = `rm -f "$FILENAME"`;
$DUMMY = `chmod 666 $OUTPUTDIR/$DOCTITLE.pdf`;
