Skip to content

schwarmdigital/factur-x.js

Repository files navigation

Factur-X

NPM version MIT License PRs welcome

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.

Usage

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.

FacturX.fromPDF

const pdf = await fs.readFile('./e-invoice.pdf')
const doc = await FacturX.fromPDF(pdf)

FacturX.fromXML

const xml = await fs.readFile('./invoice-data.xml', 'utf-8')
const doc = await FacturX.fromXML(xml)

FacturX.fromObject

const doc = await FacturX.fromObject({
    document: {
        id: '471102'
    },
    seller: {
        name: 'Lieferant GmbH'
    }
    // ...
})

FacturX.getPDF

const normalInvoice = await fs.readFile('./normal-invoice.pdf')
const hybridInvoice = await doc.getPDF(normalInvoice)

await fs.writeFile('./hybrid-invoice.pdf', hybridInvoice)

FacturX.getXML

const xml = await doc.getXML()
console.log(xml) // "<?xml version="1.0" encoding="UTF-8" ...

await fs.writeFile('./invoice-data.xml', xml)

FacturX.getObject

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published