+=item render OPTION => VALUE ...
+
+Fills in the template and renders it to a PDF document. Returns the
+name of the PDF file.
+
+Options are as for 'prepare', but 'from' and 'to' are meaningless.
+
+=cut
+
+# will also have options to set paper size, margins, etc.
+
+sub render {
+ my $self = shift;
+ eval "use PDF::WebKit";
+ die $@ if $@;
+ my %opt = @_;
+ my %hash = $self->prepare(%opt);
+ my $html = $hash{'html_body'};
+
+ my $tmp = 'msg'.$self->msgnum.'-'.time2str('%Y%m%d', time).'-XXXXXXXX';
+ my $dir = "$FS::UID::cache_dir/cache.$FS::UID::datasrc";
+
+ # Graphics/stylesheets should probably go in /var/www on the Freeside
+ # machine.
+ my $kit = PDF::WebKit->new(\$html); #%options
+ # hack to use our wrapper script
+ $kit->configure(sub { shift->wkhtmltopdf('freeside-wkhtmltopdf') });
+ my $fh = File::Temp->new(
+ TEMPLATE => $tmp,
+ DIR => $dir,
+ UNLINK => 0,
+ SUFFIX => '.pdf'
+ );
+
+ print $fh $kit->to_pdf;
+ close $fh;
+ return $fh->filename;
+}
+
+=item print OPTIONS
+
+Render a PDF and send it to the printer. OPTIONS are as for 'render'.
+
+=cut
+
+sub print {
+ my( $self, %opt ) = @_;
+ my $file = $self->render(%opt);
+
+ my $lpr = $conf->config('lpr', $opt{'cust_main'}->agentnum );
+
+ run ( $lpr, '<', $file)
+ or die "lpr error:\n$?\n";
+}
+