diff --git a/examples/example.pdf b/examples/example.pdf index 28461b9..67bb8c6 100644 Binary files a/examples/example.pdf and b/examples/example.pdf differ diff --git a/examples/index.js b/examples/index.js index 7ae451a..a2ef05f 100644 --- a/examples/index.js +++ b/examples/index.js @@ -22,7 +22,7 @@ let myInvoice = new MicroInvoice({ value : 1 }, { label : "Status", - value : "Paid" + value : "Paid afsdf asfdasd asf asdf as asdfasdf asd asd fasf" }, { label : "Date", value : "22/10/21" @@ -78,13 +78,11 @@ let myInvoice = new MicroInvoice({ value : "Description" }, { value : "Quantity" - }, { - value : "Subtotal" }], parts : [ [{ - value : "Nike Air Max" + value : "Nike Air Max Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit" }, { value : 1 }, { @@ -102,29 +100,14 @@ let myInvoice = new MicroInvoice({ }] ], - total : [{ - label : "Total without VAT", - value : "43", - price : true - }, { - label : "VAT Rate", - value : "20%" - }, { - label : "VAT Paid", - value : "8.6", - price : true - }, { - label : "Total paid with VAT", - value : "51.6", - price : true - }] + total : [] } } } }); // Render invoice as PDF -myInvoice.generate("example.pdf").then(() => { +myInvoice.generate("examples/example.pdf").then(() => { console.log("Invoice saved"); }).catch((error) => { console.error(error); diff --git a/lib/index.js b/lib/index.js index 03d5fb8..62bd5e6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -45,7 +45,7 @@ module.exports = class Microinvoice { }, header : { backgroundColor : "#F8F8FA", - height : 150, + height : 120, image : null, textPosition : 330 }, @@ -88,12 +88,12 @@ module.exports = class Microinvoice { }, { value : "Quantity" }, { - value : "Subtotal" + value : "" }], parts : [], total : [{ - label : "Total", - value : 0 + label : "", + value : "" }] }, legal : [] @@ -246,41 +246,46 @@ module.exports = class Microinvoice { ); } - let _fontMargin = 4; + let _fontMargin = 2; // Write header details this.setCursor("x", this.options.style.header.textPosition); this.setCursor("y", this.options.style.document.marginTop); + this.setText(this.options.data.invoice.name, { fontSize : "heading", fontWeight : "bold", color : this.options.style.header.regularColor }); + let currentY = this.storage.cursor.y + const currentX = this.storage.cursor.x + this.options.data.invoice.header.forEach(line => { + currentY = this.storage.cursor.y this.setText(`${line.label}:`, { fontWeight : "bold", color : this.options.style.header.regularColor, - marginTop : _fontMargin + marginTop : _fontMargin, + skipDown: true }); - let _values = []; + this.setCursor('x', currentX + 100) + this.setCursor('y', currentY) + - if (Array.isArray(line.value)) { - _values = line.value; - } else { - _values = [line.value]; - } + this.setText(line.value, { + colorCode : "secondary", + color : this.options.style.header.secondaryColor, + marginTop : _fontMargin, + maxWidth : 145, + }) - _values.forEach((value) => { - this.setText(value, { - colorCode : "secondary", - color : this.options.style.header.secondaryColor, - marginTop : _fontMargin - }); - }); + this.setCursor('x', currentX) + }); + } /** @@ -341,10 +346,6 @@ module.exports = class Microinvoice { generateTableRow(type, columns) { let _fontWeight = "normal", _colorCode = "secondary"; - this.storage.cursor.y = this.document.y; - - this.storage.cursor.y += 17; - if (type === "header") { _fontWeight = "bold"; _colorCode = "primary"; @@ -397,12 +398,10 @@ module.exports = class Microinvoice { } }); - // Set y to the max y position this.setCursor("y", _maxY); - if (type === "header") { - this.generateLine(); - } + this.generateLine(); + } /** @@ -412,7 +411,6 @@ module.exports = class Microinvoice { * @return void */ generateLine() { - this.storage.cursor.y += this.options.style.text.regularSize + 2; this.document .strokeColor("#F0F0F0") @@ -426,6 +424,9 @@ module.exports = class Microinvoice { this.storage.cursor.y ) .stroke(); + + this.setCursor("y", this.storage.cursor.y + 5); + } /** @@ -452,7 +453,7 @@ module.exports = class Microinvoice { this.generateTableRow("row", part); }); - this.storage.cursor.y += 50; + this.storage.cursor.y += 10; (this.options.data.invoice.details.total || []).forEach(total => { let _mainRatio = 0.6, _secondaryRatio = 0.3; @@ -488,7 +489,7 @@ module.exports = class Microinvoice { * @return void */ generateLegal() { - this.storage.cursor.y += 60; + this.storage.cursor.y += 15; (this.options.data.invoice.legal || []).forEach(legal => { this.setCursor("x", this.options.style.document.marginLeft * 2);