X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4b6fd7d022e006a1309d60b1a044b0f0fec28ef0..0fba3edda47fca21bedb14eb88e0f5f8d983bb38:/SL/Template/HTML.pm diff --git a/SL/Template/HTML.pm b/SL/Template/HTML.pm new file mode 100644 index 000000000..1fa725237 --- /dev/null +++ b/SL/Template/HTML.pm @@ -0,0 +1,123 @@ +package SL::Template::HTML; + +use SL::Template::LaTeX; + +use vars qw(@ISA); +@ISA = qw(SL::Template::LaTeX); + +use strict; + +sub new { + my $type = shift; + + return $type->SUPER::new(@_); +} + +sub format_string { + my ($self, $variable) = @_; + my $form = $self->{"form"}; + + $variable = $main::locale->quote_special_chars('Template/HTML', $variable); + + # Allow some HTML markup to be converted into the output format's + # corresponding markup code, e.g. bold or italic. + my @markup_replace = ('b', 'i', 's', 'u', 'sub', 'sup'); + + foreach my $key (@markup_replace) { + $variable =~ s/\<(\/?)${key}\>/<$1${key}>/g; + } + + return $variable; +} + +sub get_mime_type() { + my ($self) = @_; + + if ($self->{"form"}->{"format"} =~ /postscript/i) { + return "application/postscript"; + } elsif ($self->{"form"}->{"format"} =~ /pdf/i) { + return "application/pdf"; + } else { + return "text/html"; + } +} + +sub uses_temp_file { + my ($self) = @_; + + if ($self->{"form"}->{"format"} =~ /postscript/i) { + return 1; + } elsif ($self->{"form"}->{"format"} =~ /pdf/i) { + return 1; + } else { + return 0; + } +} + +sub convert_to_postscript { + my ($self) = @_; + my ($form, $userspath) = ($self->{"form"}, $self->{"userspath"}); + + # Convert the HTML file to postscript + + if (!chdir("$userspath")) { + $self->{"error"} = "chdir : $!"; + $self->cleanup(); + return 0; + } + + $form->{"tmpfile"} =~ s/\Q$userspath\E\///g; + my $psfile = $form->{"tmpfile"}; + $psfile =~ s/.html/.ps/; + if ($psfile eq $form->{"tmpfile"}) { + $psfile .= ".ps"; + } + + system("html2ps -f html2ps-config < $form->{tmpfile} > $psfile"); + if ($?) { + $self->{"error"} = $form->cleanup(); + $self->cleanup(); + return 0; + } + + $form->{"tmpfile"} = $psfile; + + $self->cleanup(); + + return 1; +} + +sub convert_to_pdf { + my ($self) = @_; + my ($form, $userspath) = ($self->{"form"}, $self->{"userspath"}); + + # Convert the HTML file to PDF + + if (!chdir("$userspath")) { + $self->{"error"} = "chdir : $!"; + $self->cleanup(); + return 0; + } + + $form->{"tmpfile"} =~ s/\Q$userspath\E\///g; + my $pdffile = $form->{"tmpfile"}; + $pdffile =~ s/.html/.pdf/; + if ($pdffile eq $form->{"tmpfile"}) { + $pdffile .= ".pdf"; + } + + system("html2ps -f html2ps-config < $form->{tmpfile} | ps2pdf - $pdffile"); + if ($?) { + $self->{"error"} = $form->cleanup(); + $self->cleanup(); + return 0; + } + + $form->{"tmpfile"} = $pdffile; + + $self->cleanup(); + + return 1; +} + +1;