Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
PDF returned from Remote method Loopback is corrupted

I am trying to return a file from my remote method:

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' },
  });

And the code to generate pdf is :

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);
});

But the pdf recieve is corrupted. What i am doing wrong here ? any help will be appreciated. The package i am using is html-pdf-node

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm using a different package to render pdf (jsreport) but the headers should not differ:

res.set('Content-Type', renderedData.headers['content-type']);
res.set('Content-Disposition', renderedData.headers['content-disposition']);
res.set('Content-Transfer-Encoding', 'binary');

Try to add the "Content-Transfer-Encoding" one.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!