Node-html-pdf: Broken PDF generated in server

Created on 30 Apr 2018  路  4Comments  路  Source: marcbachmann/node-html-pdf

I am developing a nodejs application which works fine when I run on localhost, but I get a blank PDF after uploading it to AWS serverless. That's my code:

pdf.create(html,{"format": "A4"}).toStream(function(err, stream){ res.writeHead(200, {"Content-type": "application/pdf"}); stream.pipe(res); });

It's not actually a blank PDF, but the content is considerably different. The same thing happens if I choose buffer instead of stream.

Most helpful comment

same problem for me. I am sending my entire html into node api which uses html-pdf to generate pdf. In local its works like charm. But after deployment my pdf looks weired. Fonts are too bigger and alignment is all gone.

All 4 comments

same problem for me. I am sending my entire html into node api which uses html-pdf to generate pdf. In local its works like charm. But after deployment my pdf looks weired. Fonts are too bigger and alignment is all gone.

I got the same issue, not sure need any configuration in server?

Ive got the same issue. A blank pdf is generated when piping to client side. Is there a way to compress the stream before piping?

Ive got the same issue. A blank pdf is generated when piping to client side. Is there a way to compress the stream before piping?

I had an issue where the PDF was corrupted during output from server to client. I managed to fix it by adding a gzip transform pipe prior to piping to res.

Here's the gist:

const { createGzip } = require('zlib')

  res.writeHead(200, {
    'Content-Type': 'application/pdf; charset=utf-8',
    'Content-Disposition': 'attachment; filename=some_doc.pdf;',
    'Content-Encoding': 'gzip'
  })

  pdf.create(html, options).toStream((err, stream) => {
    if (err) {
      console.log(err)
      return res.sendStatus(500)
    } else {
      stream.pipe(createGzip()).pipe(res)
    }
  })
Was this page helpful?
0 / 5 - 0 ratings

Related issues

tsp1996 picture tsp1996  路  5Comments

rayax86 picture rayax86  路  5Comments

RodolfoSilva picture RodolfoSilva  路  3Comments

cmoulliard picture cmoulliard  路  3Comments

ZBilel picture ZBilel  路  4Comments