0

リモートメソッドからファイルを返そうとしています:

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です

4

1 に答える 1