<%doc>
# 
# $Id: html2pdf.ipfc,v 1.2 2002/01/22 13:47:47 adulau Exp $
#
# html2pdf.ipfc is quick and ... to generate on-fly pdf from the html source file
#
# Author : Alexandre Dulaunoy

# Copyright (C) 2001,2002 Alexandre Dulaunoy <alex@thinkingsecure.com>
# Copyright (C) 2001,2002 Conostix S.A. Luxembourg <ipfc@conostix.com>

# 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# 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.
#
</%doc>

<%args>
$data

</%args>

<%perl>

my %specialChars=(
  "'","&acute;",
  "\$","\\\$",
  "\@","\\\@",
  "\!","\\\!",
  "\n","",
  "\r","");
my $specialCharList=join("",keys %specialChars);
$data=~s/\\/\\\\\\\\/g;
$data=~s/([$specialCharList])/$specialChars{$1}/g;


if ($data) {
  my $filename = $$.".html";
  open (FILEOUT, ">/tmp/$filename");
  print FILEOUT $data;
  close (FILEOUT);
  system("html2ps /tmp/$filename >/tmp/$filename.ps");
  $filename = $filename.".ps";
  my $filenamepdf = $filename.".pdf";
  system("/usr/bin/ps2pdf /tmp/$filename /tmp/$filenamepdf");
  my $command="`cat /tmp/$filenamepdf`";
  print eval($command);
}

</%perl>

