pdfkit-table
Advanced tools
Comparing version 0.1.81 to 0.1.82
83
index.js
@@ -119,6 +119,7 @@ // jshint esversion: 6 | ||
this.firstLineHeight = 0; | ||
this.tableHasInitialize = false; | ||
this.lockAddPage = true; | ||
this.lockAddTitles = false; // to addd title one time | ||
this.lockAddPage = false; | ||
this.lockAddHeader = false; | ||
this.pageNumberPerTable = 0; | ||
this.pageNumber = this.pageNumber || 0; | ||
this.pageNumber = this.pageNumber || 0; | ||
@@ -160,3 +161,3 @@ // reset position to margins.left | ||
// add a new page before crate table | ||
options.addPage === true && this.addPage(); | ||
options.addPage === true && this.emitter.emit('addPage'); //this.addPage(); | ||
@@ -180,2 +181,4 @@ // // create title and subtitle | ||
rowBottomY = 0; | ||
// this.lockAddHeader || addHeader(); | ||
this.addPage(); | ||
addHeader(); | ||
@@ -185,9 +188,8 @@ }; | ||
// add fire | ||
this.on('pageAdded', onFirePageAdded); | ||
// this.emitter.removeAllListeners(); | ||
this.emitter.removeAllListeners(); | ||
// this.emitter.on('addTitle', addTitle); | ||
// this.emitter.on('addSubtitle', addSubTitle); | ||
// this.emitter.on('firstLineDontFit', firstLineDontFit); | ||
// this.emitter.emit('firstLineDontFit'); | ||
this.emitter.on('addPage', onFirePageAdded); | ||
// this.emitter.emit('addPage'); | ||
// this.on('pageAdded', onFirePageAdded); | ||
@@ -446,13 +448,20 @@ // warning - eval can be harmful | ||
} | ||
// console.log(this.firstLineHeight); | ||
} | ||
this.titleHeight = !this.tableHasInitialize ? 24.1 : 0; | ||
// 24.1 is height calc title + subtitle | ||
this.titleHeight = !this.lockAddTitles ? 24.1 : 0; | ||
// calc if header + first line fit on last page | ||
const calc = startY + this.titleHeight + 1.2 * (this.headerHeight + this.firstLineHeight); | ||
// console.log(calc, maxY, this.titleHeight); | ||
if(calc > maxY && !this.lockAddPage) { | ||
// console.log('Header+Rows[0] no fit' ); | ||
// content is big text (crazy!) | ||
if(this.firstLineHeight > maxY) { | ||
// this.lockAddHeader = true; | ||
this.lockAddPage = true; | ||
this.addPage(); | ||
// console.log('CRAZY! This a big text on cell'); | ||
} else if(calc > maxY) { // && !this.lockAddPage | ||
// this.lockAddHeader = false; | ||
this.lockAddPage = true; | ||
this.emitter.emit('addPage'); //this.addPage(); | ||
// console.log('hmmm addPage'); | ||
return; | ||
@@ -462,3 +471,3 @@ } | ||
// if has title | ||
if(this.tableHasInitialize === false) { | ||
if(this.lockAddTitles === false) { | ||
@@ -479,3 +488,3 @@ // create title and subtitle | ||
this.tableHasInitialize = true; | ||
this.lockAddTitles = true; | ||
@@ -491,3 +500,3 @@ // this options is trial | ||
// Check to have enough room for header and first rows. default 3 | ||
// if (startY + 2 * this.headerHeight >= maxY) this.addPage(); | ||
// if (startY + 2 * this.headerHeight >= maxY) this.emitter.emit('addPage'); //this.addPage(); | ||
@@ -593,3 +602,3 @@ if(table.headers.length > 0) { | ||
separationsRow('header', startX, rowBottomY); | ||
}; | ||
@@ -608,7 +617,11 @@ | ||
// if (startY + 2 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows | ||
// else this.addPage(); | ||
if(startY + 2 * rowHeight >= maxY && !this.lockAddPage) this.addPage(); | ||
// else this.emitter.emit('addPage'); //this.addPage(); | ||
if(startY + 2 * rowHeight >= maxY && !this.lockAddPage) this.emitter.emit('addPage'); //this.addPage(); | ||
// calc position | ||
startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows | ||
// unlock add page function | ||
this.lockAddPage = false; | ||
const rectRow = { | ||
@@ -724,3 +737,9 @@ x: startX, | ||
rowBottomY = Math.max(startY + rowHeight, rowBottomY); | ||
// console.log(this.page.height, rowBottomY, this.y); | ||
// text is so big as page (crazy!) | ||
if(rowBottomY > this.page.height) { | ||
rowBottomY = this.y + columnSpacing + (rowDistance * 2); | ||
} | ||
// Separation line between rows | ||
@@ -744,11 +763,15 @@ separationsRow('horizontal', startX, rowBottomY); | ||
const rowHeight = computeRowHeight(row); | ||
// Switch to next page if we cannot go any further because the space is over. | ||
// For safety, consider 3 rows margin instead of just one | ||
// if (startY + 3 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows | ||
// else this.addPage(); | ||
if(startY + 2 * rowHeight >= maxY && !this.lockAddPage) this.addPage(); | ||
// else this.emitter.emit('addPage'); //this.addPage(); | ||
if(startY + 2 * rowHeight >= maxY && !this.lockAddPage) this.emitter.emit('addPage'); //this.addPage(); | ||
// calc position | ||
startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows | ||
this.lockAddPage = false; | ||
// unlock add page function | ||
this.lockAddPage = false; | ||
const rectRow = { | ||
@@ -823,2 +846,8 @@ x: columnPositions[0], | ||
rowBottomY = Math.max(startY + rowHeight, rowBottomY); | ||
// console.log(this.page.height, rowBottomY, this.y); | ||
// text is so big as page (crazy!) | ||
if(rowBottomY > this.page.height) { | ||
rowBottomY = this.y + columnSpacing + (rowDistance * 2); | ||
} | ||
@@ -825,0 +854,0 @@ // Separation line between rows |
{ | ||
"name": "pdfkit-table", | ||
"version": "0.1.81", | ||
"version": "0.1.82", | ||
"description": "PdfKit Table. Helps to draw informations in simple tables using pdfkit. #server-side. Generate pdf tables with javascript (PDFKIT plugin) ", | ||
@@ -29,4 +29,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"pdfkit": "latest" | ||
"pdfkit": "latest", | ||
"pdfkit-table": "^0.1.81" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47983
685
2
+ Addedpdfkit-table@^0.1.81