我正在尝试从我的远程方法返回一个文件:
Visitor.remoteMethod('getVisitorsPDF', {
description: 'Get visitors list in PDF file',
accepts: [
{ arg: 'res', type: 'object', http: { source: 'res' } },
{ arg: 'dateInStart', type: 'string' },
{ arg: 'dateInEnd', type: 'string' },
{ arg: 'employeeSiteId', type: 'string' },
{ arg: 'name', type: 'string' },
{ arg: 'visitorCompany', type: 'string' },
{ arg: 'employeeName', type: 'string' },
{ arg: 'typeId', type: 'number' },
{ arg: 'shift', type: 'number' },
],
returns: {},
http: { path: '/getpdf', verb: 'get' },
});
生成pdf的代码是:
res.set('Content-Type', 'application/octet-stream');
res.set('Content-Disposition', 'attachment;filename="visitors.pdf"');
let options = { format: 'A4' };
// Example of options with args //
// let options = { format: 'A4', args: ['--no-sandbox', '--disable-setuid-sandbox'] };
let file = { content: "<h1>Welcome to html-pdf-node</h1>" };
// or //
let file = { url: "https://example.com" };
html_to_pdf.generatePdf(file, options).then(pdfBuffer => {
console.log("PDF Buffer:-", pdfBuffer);
res.send(pdfBuffer);
});
但是pdf接收已损坏。我在这里做错了什么?任何帮助将不胜感激。我使用的包是html-pdf-node