我正在从我的 Meteor 生成一些基于 html 的报告应用程序。在我的开发机器上,一切都运行得很好,但是当我将其推送到服务器时,返回的 pdf 文件是空的。
我已经按照说明安装了 wkhtmltopdf 0.11 in this post 。我也尝试过0.9.9。当我打印时,我没有收到任何错误:只是一个没有任何内容的 pdf 文件。
任何关于我做错了什么的建议将不胜感激!
这是我用来生成 pdf 的代码:
Router.route('/reports/printHTML/:fileID?', {
name: 'reports.printHTML',
where: 'server',
action: function(){
var headers = {
'Content-type': 'application/pdf',
'Content-Disposition': "attachment; filename=space_report_" + this.params.fileID + ".pdf"
};
this.response.writeHead(200, headers);
var wk = Meteor.npmRequire('wkhtmltopdf');
var thisReport = PastReports.findOne({_id: this.params.fileID});
if(thisReport){
var html = thisReport.body + '<head><link rel="stylesheet" href="' + Meteor.absoluteUrl() + '/bootstrap.css"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.6/fullcalendar.min.css"></head>';
var r = wk(html, {pageSize:'letter', orientation:'Landscape', zoom:1, B:"5mm", L:"5mm", R:"5mm", T:"5mm",}).pipe(this.response);
} else {
console.log("No report to print: " + this.params.fileID);
}
} });
最佳答案
运行 meteor 应用程序的用户的 PATH
中应该有 wkhtmltopdf
,因此您可能需要尝试以下操作:
以运行 Meteor 应用程序的用户身份登录,并使用
which wkhtmltopdf
或验证
>whereis wkhtmltopdfwkhtmltopdf
所在的 PATH以运行 Meteor 应用程序的用户身份登录,并使用
echo $PATH
验证您的 PATH将您的 PATH 设置为包含
使用的相同路径wkhtmltopdf
# 位于 ~/.bashrc 或 ~/.bash_profile
导出 PATH="$PATH:/usr/local/bin"
或者,您可以创建一个指向
wkhtmltopdf
到 PATH 中现有目录的符号链接(symbolic link)。 如果wkhtmltopdf
安装在/usr/local/bin
下,并且您的PATH
中已有/usr/bin
:ln -s/usr/local/bin/wkhtmltopdf/usr/bin/wkhtmltopdf
此外,请务必检查浏览器的控制台或服务器日志是否有错误。
关于meteor - wkhtmltopdf 和 Meteor 返回空白 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28971405/