Estoy tratando de devolver un archivo desde mi método remoto:
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' }, });Y el código para generar pdf es:
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); });Pero el pdf recibido está dañado. ¿Qué estoy haciendo mal aquí? cualquier ayuda será apreciada. El paquete que estoy usando es html-pdf-node
Estoy usando un paquete diferente para renderizar pdf (jsreport) pero los encabezados no deberían diferir:
res.set('Content-Type', renderedData.headers['content-type']); res.set('Content-Disposition', renderedData.headers['content-disposition']); res.set('Content-Transfer-Encoding', 'binary');Intente agregar el "Codificación de transferencia de contenido".