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

382
Views
How to convert HTML to PDF and share the pdf file with expo react native share (ios) with printToFileAsync

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

about 4 years ago · Juan Pablo Isaza
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!