Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 1.25 KB

README.md

File metadata and controls

36 lines (28 loc) · 1.25 KB

This module generates a PDF stream from a 🇮🇹 Digital invoice XML string input

TLDR

from HERE to THERE

Example inside your express request

  request.get(fileUri, async (error, response, body) => {
    if (error) return 'Remember to manage Errors'

    try {
      const result = await xmlToPDF(body)
      try {
        // RES
        res.set('Content-Type', 'application/pdf')
        result.pipe(res)
      } catch (e) {
        console.log(`Error occurred while rendering: ${e}`)
        res.status(500).end()
      }
    } catch (error) {
      logger.error(error)
      res.status(500)
      res.send({ error: 'Failed to parse XML', message: error.message })
    }
  })
}

The module exports also:

a simple xmlToJson function that uses XML2JS and returns a typed JSON (check the types DigitalInvoiceJson in types folder)

the function xmlToCompactJson that transform the previous DigitalInvoiceJson in a more consistent and smaller DigitalInvoice (check the types DigitalInvoice in types folder)