From 0fd894c50eaa84169115ccbb682a53f5148a8c9c Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 11 Jan 2004 23:59:20 +0000 Subject: [PATCH] typeset invoice view in web UI uses pdf instead of postscript, closes Bug#614 --- FS/FS/cust_bill.pm | 84 ++++++++++++++++++++++++++++++++++++++----- httemplate/view/cust_bill.cgi | 2 +- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 8adbb6c1d..a5602a708 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -888,9 +888,12 @@ sub print_text { } -=item print_ps [ TIME [ , TEMPLATE ] ] +=item print_latex [ TIME [ , TEMPLATE ] ] -Returns an postscript invoice, as a scalar. +Internal method - returns a filename of a filled-in LaTeX template for this +invoice (Note: add ".tex" to get the actual filename). + +See print_ps and print_pdf for methods that return PostScript and PDF output. TIME an optional value used to control the printing of overdue messages. The default is now. It isn't the date of the invoice; that's the `_date' field. @@ -900,7 +903,7 @@ L and L for conversion functions. =cut #still some false laziness w/print_text -sub print_ps { +sub print_latex { my( $self, $today, $template ) = @_; $today ||= time; @@ -1070,17 +1073,37 @@ sub print_ps { print TEX join("\n", @filled_in ), "\n"; close TEX; + return $file; + +} + +=item print_ps [ TIME [ , TEMPLATE ] ] + +Returns an postscript invoice, as a scalar. + +TIME an optional value used to control the printing of overdue messages. The +default is now. It isn't the date of the invoice; that's the `_date' field. +It is specified as a UNIX timestamp; see L. Also see +L and L for conversion functions. + +=cut + +sub print_ps { + my $self = shift; + + my $file = $self->print_latex(@_); + #error checking!! system('pslatex', "$file.tex"); system('pslatex', "$file.tex"); - #system('dvips', '-t', 'letter', "$file.dvi", "$file.ps"); - system('dvips', '-t', 'letter', "$file.dvi", '-o', "$file.ps" ); + system('dvips', '-q', '-t', 'letter', "$file.dvi", '-o', "$file.ps" ); - open(POSTSCRIPT, "<$file.ps") or die "can't open $file.ps (probable error in LaTeX template): $!\n"; + open(POSTSCRIPT, "<$file.ps") + or die "can't open $file.ps (probable error in LaTeX template): $!\n"; #rm $file.dvi $file.log $file.aux - #unlink("$file.dvi", "$file.log", "$file.aux", "$file.ps"); - unlink("$file.dvi", "$file.log", "$file.aux"); + unlink("$file.dvi", "$file.log", "$file.aux", "$file.ps"); + #unlink("$file.dvi", "$file.log", "$file.aux"); my $ps = ''; while () { @@ -1093,7 +1116,50 @@ sub print_ps { } -# quick subroutine for print_ps +=item print_pdf [ TIME [ , TEMPLATE ] ] + +Returns an PDF invoice, as a scalar. + +TIME an optional value used to control the printing of overdue messages. The +default is now. It isn't the date of the invoice; that's the `_date' field. +It is specified as a UNIX timestamp; see L. Also see +L and L for conversion functions. + +=cut + +sub print_pdf { + my $self = shift; + + my $file = $self->print_latex(@_); + + #system('pdflatex', "$file.tex"); + #system('pdflatex', "$file.tex"); + #! LaTeX Error: Unknown graphics extension: .eps. + + #error checking!! + system('pslatex', "$file.tex"); + system('pslatex', "$file.tex"); + + #system('dvipdf', "$file.dvi", "$file.pdf" ); + system("dvips -q -t letter -f $file.dvi | gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$file.pdf -c save pop -"); + + open(PDF, "<$file.pdf") + or die "can't open $file.pdf (probably error in LaTeX tempalte: $!\n"; + + unlink("$file.dvi", "$file.log", "$file.aux", "$file.pdf"); + + my $pdf = ''; + while () { + $pdf .= $_; + } + + close PDF; + + return $pdf; + +} + +# quick subroutine for print_latex # # There are ten characters that LaTeX treats as special characters, which # means that they do not simply typeset themselves: diff --git a/httemplate/view/cust_bill.cgi b/httemplate/view/cust_bill.cgi index ddc92748d..4e0c4383b 100755 --- a/httemplate/view/cust_bill.cgi +++ b/httemplate/view/cust_bill.cgi @@ -23,7 +23,7 @@ print qq!Enter payments (check/cash) aga print qq!Reprint this invoice!. '

'; print menubar( - 'View typeset invoice' => "${p}view/cust_bill-ps.cgi?$invnum", + 'View typeset invoice' => "${p}view/cust_bill-pdf.cgi?$invnum", ), '

'; #false laziness with search/cust_bill_event.cgi -- 2.11.0