Bil*_*eni 17 node.js html-pdf node-html-pdf
我有一个使用 html-pdf 包的简单项目,我想用以下代码制作一个简单的 pdf 文件:
...
pdf.create(html).toStream(function(err, stream){
if (err) reject(err) ;
else stream.pipe(fs.createWriteStream(path.join(__dirname, '../../../assets/docs/idv_docs/')+data.link+'.pdf'));
});
...
Run Code Online (Sandbox Code Playgroud)
但我收到此错误消息:
Error: html-pdf: Received the exit code '1'
cc-server_1 | Auto configuration failed
cc-server_1 | 139666354437760:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory
cc-server_1 | 139666354437760:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
cc-server_1 | 139666354437760:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf
cc-server_1 | 139666354437760:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_conf
cc-server_1 |
cc-server_1 | at ChildProcess.respond (/usr/src/app/node_modules/html-pdf/lib/pdf.js:121:31)
cc-server_1 | at ChildProcess.emit (events.js:311:20)
cc-server_1 | at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Run Code Online (Sandbox Code Playgroud)
小智 43
childprocess将被粘贴到 phantomJs 中pdf.create(html, {
childProcessOptions: {
env: {
OPENSSL_CONF: '/dev/null',
},
}
});
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,问题是 openssl.cnf 文件。
我的操作系统是 Debian 10。
请尝试以下步骤
步骤 1:转到 /etc/ssl/openssl.cnf
步骤 2:找到以下行并对其进行注释。
# System default
openssl_conf = default_conf
Run Code Online (Sandbox Code Playgroud)
步骤 3:重新启动节点服务器
小智 0
我使用 create it 为我工作
//pdf.js
const pdf = require('html-pdf');
function toPDF (html, options, output) {
return new Promise(function (resolve, reject) {
pdf.create(html, options).toFile(output, function(error, response) {
if (error) {
reject(error);
}
else {
resolve(response);
}
});
});
}
module.exports = {
toPDF: toPDF
}
Run Code Online (Sandbox Code Playgroud)
使用时
const options = { format: 'A4', base: './assets' }
const fileName = `PDFDemo-${Date.now()}`
const output = `./pdf/${fileName}.pdf`
let pdfResult = await pdfUtil.toPDF(html, options, output)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14530 次 |
| 最近记录: |