pdfkit-table
Advanced tools
Comparing version 0.1.83 to 0.1.84
113
index.js
@@ -6,3 +6,3 @@ // jshint esversion: 6 | ||
const PDFDocument = require("pdfkit"); | ||
const EventEmitter = require('events').EventEmitter; | ||
// const EventEmitter = require('events').EventEmitter; | ||
@@ -13,3 +13,3 @@ class PDFDocumentWithTables extends PDFDocument { | ||
super(option); | ||
this.emitter = new EventEmitter(); | ||
// this.emitter = new EventEmitter(); | ||
} | ||
@@ -118,9 +118,9 @@ | ||
//------------ experimental fast variables | ||
this.titleHeight = 0; | ||
this.headerHeight = 0; | ||
this.firstLineHeight = 0; | ||
this.lockAddTitles = false; // to addd title one time | ||
this.lockAddPage = false; | ||
this.lockAddHeader = false; | ||
this.safelyMarginBottom = 15; | ||
let titleHeight = 0; | ||
let headerHeight = 0; | ||
let firstLineHeight = 0; | ||
let lockAddTitles = false; // to addd title one time | ||
let lockAddPage = false; | ||
let lockAddHeader = false; | ||
let safelyMarginBottom = this.page.margins.top/2; | ||
@@ -148,3 +148,3 @@ // reset position to margins.left | ||
// }); | ||
// console.log(data, titleHeight); // 24 | ||
this.logg(data, titleHeight); // 24 | ||
@@ -163,3 +163,3 @@ // write | ||
// add a new page before crate table | ||
options.addPage === true && this.emitter.emit('addPage'); //this.addPage(); | ||
options.addPage === true && onFirePageAdded(); // this.emitter.emit('addPage'); //this.addPage(); | ||
@@ -180,12 +180,12 @@ // // create title and subtitle | ||
rowBottomY = 0; | ||
// this.lockAddHeader || addHeader(); | ||
this.addPage(); | ||
addHeader(); | ||
lockAddPage || this.addPage(); | ||
lockAddHeader || addHeader(); | ||
//addHeader(); | ||
}; | ||
// add fire | ||
this.emitter.removeAllListeners(); | ||
// this.emitter.removeAllListeners(); | ||
// this.emitter.on('addTitle', addTitle); | ||
// this.emitter.on('addSubtitle', addSubTitle); | ||
this.emitter.on('addPage', onFirePageAdded); | ||
// this.emitter.on('addPage', onFirePageAdded); | ||
// this.emitter.emit('addPage'); | ||
@@ -434,13 +434,16 @@ // this.on('pageAdded', onFirePageAdded); | ||
// calc header height | ||
if(this.headerHeight === 0){ | ||
this.headerHeight = computeRowHeight(table.headers); | ||
if(headerHeight === 0){ | ||
headerHeight = computeRowHeight(table.headers); | ||
this.logg(headerHeight, 'headers'); | ||
} | ||
// calc first table line when init table | ||
if(this.firstLineHeight === 0){ | ||
if(firstLineHeight === 0){ | ||
if(table.datas.length > 0){ | ||
this.firstLineHeight = computeRowHeight(table.datas[0]); | ||
firstLineHeight = computeRowHeight(table.datas[0]); | ||
this.logg(firstLineHeight, 'datas'); | ||
} | ||
else if(table.rows.length > 0){ | ||
this.firstLineHeight = computeRowHeight(table.rows[0]); | ||
firstLineHeight = computeRowHeight(table.rows[0]); | ||
this.logg(firstLineHeight, 'rows'); | ||
} | ||
@@ -450,15 +453,15 @@ } | ||
// 24.1 is height calc title + subtitle | ||
this.titleHeight = !this.lockAddTitles ? 24.1 : 0; | ||
titleHeight = !lockAddTitles ? 24.1 : 0; | ||
// calc if header + first line fit on last page | ||
const calc = startY + this.titleHeight + this.firstLineHeight + this.headerHeight + this.safelyMarginBottom// * 1.3; | ||
const calc = startY + titleHeight + firstLineHeight + headerHeight + safelyMarginBottom// * 1.3; | ||
// content is big text (crazy!) | ||
if(this.firstLineHeight > maxY) { | ||
// this.lockAddHeader = true; | ||
this.lockAddPage = true; | ||
// 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(); | ||
if(firstLineHeight > maxY) { | ||
// lockAddHeader = true; | ||
lockAddPage = true; | ||
this.logg('CRAZY! This a big text on cell'); | ||
} else if(calc > maxY) { // && !lockAddPage | ||
// lockAddHeader = false; | ||
lockAddPage = true; | ||
onFirePageAdded(); // this.emitter.emit('addPage'); //this.addPage(); | ||
return; | ||
@@ -468,3 +471,3 @@ } | ||
// if has title | ||
if(this.lockAddTitles === false) { | ||
if(lockAddTitles === false) { | ||
@@ -485,3 +488,3 @@ // create title and subtitle | ||
this.lockAddTitles = true; | ||
lockAddTitles = true; | ||
@@ -497,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.emitter.emit('addPage'); //this.addPage(); | ||
// if (startY + 2 * headerHeight >= maxY) this.emitter.emit('addPage'); //this.addPage(); | ||
@@ -510,3 +513,3 @@ if(table.headers.length > 0) { | ||
// width: columnWidth, | ||
// height: this.headerHeight + columnSpacing, | ||
// height: headerHeight + columnSpacing, | ||
// }; | ||
@@ -525,3 +528,3 @@ | ||
width: columnSizes[i], | ||
height: this.headerHeight + columnSpacing, | ||
height: headerHeight + columnSpacing, | ||
}; | ||
@@ -535,2 +538,3 @@ | ||
// write | ||
this.text(header, | ||
@@ -563,3 +567,21 @@ lastPositionX + (cellPadding.left), | ||
} | ||
// # Rotation | ||
// var doTransform = function (x, y, angle) { | ||
// var rads = angle / 180 * Math.PI; | ||
// var newX = x * Math.cos(rads) + y * Math.sin(rads); | ||
// var newY = y * Math.cos(rads) - x * Math.sin(rads); | ||
// return { | ||
// x: newX, | ||
// y: newY, | ||
// rads: rads, | ||
// angle: angle | ||
// }; | ||
// }; | ||
// } | ||
// this.save(); // rotation | ||
// this.rotate(90, {origin: [lastPositionX, startY]}); | ||
// width = 50; | ||
// background header | ||
@@ -570,5 +592,5 @@ const rectCell = { | ||
width: width, | ||
height: this.headerHeight + columnSpacing, | ||
height: headerHeight + columnSpacing, | ||
}; | ||
// add background | ||
@@ -587,4 +609,5 @@ this.addBackground(rectCell, headerColor, headerOpacity); | ||
}) | ||
lastPositionX += width; | ||
// this.restore(); // rotation | ||
@@ -615,2 +638,3 @@ }); | ||
const rowHeight = computeRowHeight(row); | ||
this.logg(rowHeight); | ||
@@ -621,3 +645,3 @@ // Switch to next page if we cannot go any further because the space is over. | ||
// else this.emitter.emit('addPage'); //this.addPage(); | ||
if(this.y + this.safelyMarginBottom + rowHeight >= maxY && !this.lockAddPage) this.emitter.emit('addPage'); //this.addPage(); | ||
if(this.y + safelyMarginBottom + rowHeight >= maxY && !lockAddPage) onFirePageAdded(); // this.emitter.emit('addPage'); //this.addPage(); | ||
@@ -628,3 +652,3 @@ // calc position | ||
// unlock add page function | ||
this.lockAddPage = false; | ||
lockAddPage = false; | ||
@@ -766,2 +790,3 @@ const rectRow = { | ||
const rowHeight = computeRowHeight(row); | ||
this.logg(rowHeight); | ||
@@ -772,3 +797,3 @@ // Switch to next page if we cannot go any further because the space is over. | ||
// else this.emitter.emit('addPage'); //this.addPage(); | ||
if(this.y + this.safelyMarginBottom + rowHeight >= maxY && !this.lockAddPage) this.emitter.emit('addPage'); //this.addPage(); | ||
if(this.y + safelyMarginBottom + rowHeight >= maxY && !lockAddPage) onFirePageAdded(); // this.emitter.emit('addPage'); //this.addPage(); | ||
@@ -779,3 +804,3 @@ // calc position | ||
// unlock add page function | ||
this.lockAddPage = false; | ||
lockAddPage = false; | ||
@@ -782,0 +807,0 @@ const rectRow = { |
{ | ||
"name": "pdfkit-table", | ||
"version": "0.1.83", | ||
"version": "0.1.84", | ||
"description": "PdfKit Table. Helps to draw informations in simple tables using pdfkit. #server-side. Generate pdf tables with javascript (PDFKIT plugin) ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
48801
702