Socket
Socket
Sign inDemoInstall

pdfkit-table

Package Overview
Dependencies
67
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.77 to 0.1.78

123

index.js

@@ -6,2 +6,3 @@ // jshint esversion: 6

const PDFDocument = require("pdfkit");
const EventEmitter = require('events').EventEmitter;

@@ -12,2 +13,3 @@ class PDFDocumentWithTables extends PDFDocument {

super(option);
this.emitter = new EventEmitter();
}

@@ -115,2 +117,11 @@

//------------ experimental fast variables
this.titleHeight = 0;
this.headerHeight = 0;
this.firstLineHeight = 0;
this.tableHasInitialize = false;
this.lockAddPage = true;
this.pageNumberPerTable = 0;
this.pageNumber = this.pageNumber || 0;
// reset position to margins.left

@@ -131,8 +142,10 @@ if( options.x === null || options.x === -1 ){

// font size
this.fontSize( size ).opacity( opacity );
// get height line
// cellHeight = this.heightOfString( data, {
// width: usableWidth,
// align: "left",
this.fillColor('black').font("Helvetica").fontSize(8).fontSize(size).opacity(opacity).fill();
// const titleHeight = this.heightOfString(data, {
// width: tableWidth,
// align: 'left',
// });
// console.log(data, titleHeight); // 24
// write

@@ -152,12 +165,16 @@ this.text( data, startX, startY ).opacity( 1 ); // moveDown( 0.5 )

// create title and subtitle
createTitle( title, 12, 1 );
createTitle( subtitle, 9, 0.7 );
// // create title and subtitle
// createTitle( title, 12, 1 );
// createTitle( subtitle, 9, 0.7 );
// add space after title
if( title || subtitle ){
startY += 3;
}
// if( title || subtitle ){
// startY += 3;
// };
// event emitter
const onFirePageAdded = () => {
++this.pageNumberPerTable;
++this.pageNumber;
// console.log('onFirePageAdded', ++this.pageNumberPerTable, ++this.pageNumber);
// startX = this.page.margins.left;

@@ -167,7 +184,13 @@ startY = this.page.margins.top;

addHeader();
}
};
// add fire
this.on("pageAdded", onFirePageAdded);
this.on('pageAdded', onFirePageAdded);
// this.emitter.removeAllListeners();
// this.emitter.on('addTitle', addTitle);
// this.emitter.on('addSubtitle', addSubTitle);
// this.emitter.on('firstLineDontFit', firstLineDontFit);
// this.emitter.emit('firstLineDontFit');
// warning - eval can be harmful

@@ -341,2 +364,6 @@ const fEval = (str) => {

});
// if(result + columnSpacing === 0) {
// computeRowHeight(row);
// }

@@ -409,5 +436,48 @@ return result + columnSpacing;

let rowHeight = computeRowHeight(table.headers);
// lastPositionX = startX; // x position head
// calc header height
if(this.headerHeight === 0){
this.headerHeight = computeRowHeight(table.headers);
}
// calc first line
if(this.firstLineHeight === 0){
if(table.datas.length > 0){
this.firstLineHeight = computeRowHeight(table.datas[0]);
}
else if(table.rows.length > 0){
this.firstLineHeight = computeRowHeight(table.rows[0]);
}
}
this.titleHeight = !this.tableHasInitialize ? 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) {
// console.log('Header+Rows[0] no fit' );
this.lockAddPage = true;
this.addPage();
return;
}
// if has title
if(this.tableHasInitialize === false) {
// create title and subtitle
createTitle( title, 12, 1 );
createTitle( subtitle, 9, 0.7 );
// add space after title
if( title || subtitle ){
startY += 3;
};
}
// Allow the user to override style for headers
prepareHeader();
this.tableHasInitialize = true;
// this options is trial

@@ -422,3 +492,3 @@ if(options.absolutePosition === true){

// Check to have enough room for header and first rows. default 3
// if (startY + 2 * rowHeight >= maxY) this.addPage();
// if (startY + 2 * this.headerHeight >= maxY) this.addPage();

@@ -435,3 +505,3 @@ if(table.headers.length > 0) {

// width: columnWidth,
// height: rowHeight + columnSpacing,
// height: this.headerHeight + columnSpacing,
// };

@@ -450,3 +520,3 @@

width: columnSizes[i],
height: rowHeight + columnSpacing,
height: this.headerHeight + columnSpacing,
};

@@ -493,3 +563,3 @@

width: width,
height: rowHeight + columnSpacing,
height: this.headerHeight + columnSpacing,
};

@@ -544,2 +614,6 @@

startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
if(i === 0) {
// firstLineDontFit();
}

@@ -680,5 +754,6 @@ const rectRow = {

// else this.addPage();
if(startY + 2 * rowHeight >= maxY) this.addPage();
if(startY + 2 * rowHeight >= maxY && !this.lockAddPage) this.addPage();
startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
this.lockAddPage = false;
const rectRow = {

@@ -685,0 +760,0 @@ x: columnPositions[0],

2

package.json
{
"name": "pdfkit-table",
"version": "0.1.77",
"version": "0.1.78",
"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",

@@ -387,2 +387,7 @@ <p align="center">

### 0.1.78
- Avoid a table title appearing alone
- Thanks Alexis Arriola ***@AlexisArriola***
### 0.1.72

@@ -389,0 +394,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc