将HTML结果页转换为PDF并以CGI文件下载 [英] Turning HTML Results Page into PDF and Downloading in CGI file

查看:77
本文介绍了将HTML结果页转换为PDF并以CGI文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PERL中工作,并且我有一个html结果页,可以完美显示。我想添加一个按钮,使此html页面成为可下载到您计算机上的pdf。以下是生成html页面的代码。在CGI代码中生成了fileFH。

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


推荐答案

如果您愿意接受外部程序/转换的依赖性我强烈建议 http://wkhtmltopdf.org/

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

流量:


  1. 按钮单击

  2. wkhtmltopdf提供了目标URL

  3. 发送给用户的输出

您可能还希望缓存输出以减少数量

You may want to cache the output as well to reduce the number of conversions.

编辑
Perl也已经具有包装器。

EDIT Perl already has a wrapper too.

https://metacpan.org/release/PDF-WebKit

这篇关于将HTML结果页转换为PDF并以CGI文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆