Read and Write Hybrid Invoice Documents (EN 16931 / Factur-X / ZUGFeRD / eRechnung / XRechnung) in Javascript / Typescript.
🚧 This library is heavily under development - contributions are very welcome.
npm install factur-x
A Factur-X instance can be created from PDF, XML or an Object and exported to PDF, XML or an Object.
const pdf = await fs.readFile('./e-invoice.pdf')
const doc = await FacturX.fromPDF(pdf)
const xml = await fs.readFile('./invoice-data.xml', 'utf-8')
const doc = await FacturX.fromXML(xml)
const doc = await FacturX.fromObject({
document: {
id: '471102'
},
seller: {
name: 'Lieferant GmbH'
}
// ...
})
const normalInvoice = await fs.readFile('./normal-invoice.pdf')
const hybridInvoice = await doc.getPDF(normalInvoice)
await fs.writeFile('./hybrid-invoice.pdf', hybridInvoice)
const xml = await doc.getXML()
console.log(xml) // "<?xml version="1.0" encoding="UTF-8" ...
await fs.writeFile('./invoice-data.xml', xml)
const obj = await FacturX.getObject()
console.log(obj) // { document: { id: "471102" }, seller: { name: "Lieferant GmbH", ...
await fs.writeFile('./invoice-data.json', JSON.stringify(obj, null, 4))