I can generate the pdfBuffer by sending the HTML to the backend, but receiving the data and sharing it with expo share is where I‘m stuck at. Really Apreciate for any help.
The lib I'm using is
var pdf = require('html-pdf')
https://github.com/marcbachmann/node-html-pdf
I have tried the following code and search google for 4 days with no prevail.
frontend react native code
const createPdf = () => {
const html = insertHtml(orders)
axios('http://573f-98-14-177-227.ngrok.io/api/createPdf', {
method: 'post',
data: { html },
responseType: 'json',
})
.then((res) => {
console.log('pdf ', res.data)
sharePdf(res.data)
})
.catch(function (error) {
console.log('err ', error)
})
Alert.alert('Ordered Success', 'press ok to save a copy', [
{
text: 'Ok',
onPress: () => {},
style: 'cancel',
},
{
text: 'Cancel',
style: 'cancel',
},
])
props.resetOrder()
setOrders([])
}
Node backend to create the pdf
router.post('/createPdf', (req, res) => {
const {html} = req.body
pdf.create(html).toBuffer((err, buffer) => {
res.setHeader('Content-Length', buffer.length)
res.setHeader('Content-type', 'application/pdf')
var pdfBuffer = new Buffer.from(buffer)
res.send(pdfBuffer)
console.log('buffer ', pdfBuffer)
})
pdf.create(html).toStream((err, pdfStream) => {
if (err) {
console.log(err)
return res.sendStatus(500)
} else {
res.statusCode = 200
pdfStream.on('end', () => {
return res.end()
})
pdfStream.pipe(res)
}
})
})