Turning HTML Results Page into PDF and Downloading in CGI file

只谈情不闲聊 提交于 2019-12-25 07:24:16

问题


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);
}

回答1:


If you are open to an external program/dependency for the conversion I highly recommend http://wkhtmltopdf.org/

Flow:

  1. Button Click
  2. wkhtmltopdf is provided target URL
  3. Output sent to user

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



来源:https://stackoverflow.com/questions/39500817/turning-html-results-page-into-pdf-and-downloading-in-cgi-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!