I am having trouble creating a pdf that has content. I am running node/express with html-pdf to take a react Dom node converted to a string, then piped back to the client-side to save the Blob as a pdf. That pdf is blank, but has multiple pages, indicating that the content is taking up space.
The Request going in:
{"html":"<html><meta charset=\"utf8\"><title>Report</title>
<body><div>Text test</div></body></html>","filename":"report"}
The PDF creation:
pdf.create(req.body.html, {
format: 'letter'
, border: { top: '0.6in', right: '0.6in', bottom: '0.6in', left: '0.6in'}
, phantomArgs: ["--ignore-ssl-errors=yes"]
}).toStream(function(err, stream){
if(err){
utils.standardError(res, err)
}
else{
res.setHeader('Last-Modified', utilities.httpDateString(new Date()))
res.setHeader('Content-disposition', 'attachment; filename='+req.body.filename)
res.setHeader('Content-Type', 'application/pdf')
// res.setHeader('Response-type', "arrayBuffer")
// res.setHeader('Content-length', buffer.length)
res.status(200)
// res.send(buffer)
stream.pipe(res)
}
})
I am then saving the Blob as such:
saveAs(
new Blob([response], {type: "application/pdf;charset=utf-8"}),
'report.pdf'
)
When i run the saved pdf through a validator I get all kinds of errors pertaining to its formatting. What am i doing wrong?
via Fred Chapman
No comments:
Post a Comment