I am working in PERL and I have an html results page that displays perfectly. I want to add a button that makes this html page a pdf that downloads onto your machine. Below is the code that generates the html page. fileFH is generated in the CGI code.
sub searchResults {
my $data = shift;
my $file = "$OUTFILES/$data.html";
open(my $fileFH, '<', $file) or return "Can not find file\n";
print $cgi->header();
while (<$fileFH>) {
print qq($_);
}
close($fileFH);
}
If you are open to an external program/dependency for the conversion I highly recommend http://wkhtmltopdf.org/
Flow:
You may want to cache the output as well to reduce the number of conversions.
EDIT Perl already has a wrapper too.
https://metacpan.org/release/PDF-WebKit