Warm tip: This article is reproduced from serverfault.com, please click

javascript-在我的部署服务器中无法使用html-pdf创建PDF文件?

(javascript - PDF file creation using html-pdf is not working in my deployment server?)

发布于 2016-05-21 13:04:50

我正在使用html-pdf npm模块创建pdf文件,在我的本地环境(mac,windows)中一切正常。但是,当我们在亚马逊ec2服务器中部署相同的代码时,html-pdf的create()无法创建文件,也不会给我任何错误。我几乎通过异常处理,绝对路径等尝试了所有可能的方法。它们都不起作用。谁能帮我这个忙。我的代码是

function generatePdf(content, options, callback) {
    var fileName = new Date().getTime() + Math.random() + '.pdf';
    pdf.create(content, options).toFile('../uploads/' + fileName, function(error, response) {
        if (error) {
            callback(error);
        } else {
            callback({
                fileName: fileName,
                filePath: response.filename
            });
        }                                
    });
}

错误为{},响应为{}

Questioner
Syam Danda
Viewed
0
3,425 2020-08-19 05:14:05

上面的代码绝对没有错。但是,html-pdf lib不会抛出任何错误或同时创建文件pdf.create(...).toFile的原因是由于你的环境中html-pdf安装版本中的错误。我们可以通过检查确定

npm list html-pdf如果返回类似npm ERR的信息!代码1然后做

npm uninstall html-pdf and then do again
npm install html-pdf 

并重复上述步骤,以确保当前安装的html-pdf版本中没有错误。