Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda