Socket
Socket
Sign inDemoInstall

pdfkit-table

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfkit-table - npm Package Compare versions

Comparing version 0.1.46 to 0.1.47

235

index.js

@@ -132,8 +132,12 @@ // jshint esversion: 6

// add fire
this.on("pageAdded", () => {
const onFirePageAdded = () => {
// startX = this.page.margins.left;
startY = this.page.margins.top;
rowBottomY = 0;
});
addHeader();
}
// add fire
this.on("pageAdded", onFirePageAdded);
// warning - eval can be harmful

@@ -242,134 +246,144 @@ const fEval = (str) => {

// Allow the user to override style for headers
prepareHeader();
// Header
// Check to have enough room for header and first rows. default 3
if (startY + 2 * computeRowHeight(table.headers) > maxY) {
this.addPage();
}
const addHeader = () => {
let lastPosition = 0; // x position head
// Allow the user to override style for headers
prepareHeader();
if(table.headers && table.headers.length > 0){
// Check to have enough room for header and first rows. default 3
if (startY + 2 * computeRowHeight(table.headers) > maxY) {
this.addPage();
}
let rowHeight = computeRowHeight(table.headers);
let lastPosition = 0; // x position head
if(typeof table.headers[0] === 'string' ){
if(table.headers && table.headers.length > 0){
// we have columnSizes[] complete
if(columnIsDefined){
let rowHeight = computeRowHeight(table.headers);
// sum columns sizes
columnWidth = columnSizes.reduce((acc, curr, index ) => acc + curr, 0);
// background header
const rectRow = {
x: startX,
y: startY - columnSpacing - (rowDistance * 2),
width: columnWidth,
height: rowHeight + columnSpacing,
};
if(typeof table.headers[0] === 'string' ){
// add background
this.addBackground( rectRow );
// we have columnSizes[] complete
if(columnIsDefined){
lastPosition = startX;
// sum columns sizes
columnWidth = columnSizes.reduce((acc, curr, index ) => acc + curr, 0);
// background header
const rectRow = {
x: startX,
y: startY - columnSpacing - (rowDistance * 2),
width: columnWidth,
height: rowHeight + columnSpacing,
};
// print headers
table.headers.forEach((header, i) => {
// add background
this.addBackground( rectRow );
this.text(header, lastPosition, startY, {
width: columnSizes[i] >> 0,
align: "left",
lastPosition = startX;
// print headers
table.headers.forEach((header, i) => {
this.text(header, lastPosition, startY, {
width: columnSizes[i] >> 0,
align: "left",
});
columnPositions.push(lastPosition);
lastPosition += columnSizes[i] >> 0;
});
columnPositions.push(lastPosition);
lastPosition += columnSizes[i] >> 0;
} else {
});
} else {
// background header
const rectRow = {
x: startX,
y: startY - columnSpacing - (rowDistance * 2),
width: columnWidth * table.headers.length - columnSpacing,
height: rowHeight + columnSpacing,
};
// background header
const rectRow = {
x: startX,
y: startY - columnSpacing - (rowDistance * 2),
width: columnWidth * table.headers.length - columnSpacing,
height: rowHeight + columnSpacing,
};
// add background
this.addBackground( rectRow );
// print headers
table.headers.forEach((header, i) => {
// add background
this.addBackground( rectRow );
// print headers
table.headers.forEach((header, i) => {
lastPosition = startX + i * columnWidth;
this.text(header, lastPosition, startY, {
width: columnWidthFit,
align: "left",
});
lastPosition = startX + i * columnWidth;
this.text(header, lastPosition, startY, {
width: columnWidthFit,
align: "left",
columnSizes.push(columnWidthFit);
columnPositions.push(lastPosition);
});
columnSizes.push(columnWidthFit);
columnPositions.push(lastPosition);
}
}else{
});
lastPosition = startX;
}
}else{
// Print all headers
table.headers.forEach(({label, width, renderer}, i) => {
lastPosition = startX;
if(renderer && typeof renderer === 'string') {
table.headers[i].renderer = fEval(renderer);
}
// Print all headers
table.headers.forEach(({label, width, renderer}, i) => {
// force number
width = width >> 0;
// background header
const rectRow = {
x: lastPosition,
y: startY - columnSpacing - (rowDistance * 2),
width: width,
height: rowHeight + columnSpacing,
};
if(renderer && typeof renderer === 'string') {
table.headers[i].renderer = fEval(renderer);
}
// add background
this.addBackground( rectRow );
// force number
width = width >> 0;
// background header
const rectRow = {
x: lastPosition,
y: startY - columnSpacing - (rowDistance * 2),
width: width,
height: rowHeight + columnSpacing,
};
// write
this.text(label, lastPosition + 0, startY, {
width: width,
align: "left",
})
// add background
this.addBackground( rectRow );
columnSizes.push(width);
columnPositions.push(lastPosition);
lastPosition += width;
// write
this.text(label, lastPosition + 0, startY, {
width: width,
align: "left",
})
});
columnSizes.push(width);
columnPositions.push(lastPosition);
lastPosition += width;
// set style
prepareRowOptions(table.headers);
});
}
}
// set style
prepareRowOptions(table.headers);
// Refresh the y coordinate of the bottom of the headers row
rowBottomY = Math.max(startY + computeRowHeight(table.headers), rowBottomY);
}
// update table width
tableWidth = columnPositions[columnPositions.length-1] + columnSizes[columnSizes.length-1];
// Separation line between headers and rows
separationsRow(
{x: startX, y: rowBottomY},
{x: tableWidth, y: rowBottomY},
);
}
// Refresh the y coordinate of the bottom of the headers row
rowBottomY = Math.max(startY + computeRowHeight(table.headers), rowBottomY);
addHeader();
// update table width
tableWidth = columnPositions[columnPositions.length-1] + columnSizes[columnSizes.length-1];
// End header
// Separation line between headers and rows
separationsRow(
{x: startX, y: rowBottomY},
{x: tableWidth, y: rowBottomY},
);
// datas ----------------------------------------------------

@@ -383,4 +397,6 @@

// For safety, consider 3 rows margin instead of just one
if (startY + 2 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
else this.addPage();
// if (startY + 2 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
// else this.addPage();
startY + 2 * rowHeight >= maxY && this.addPage();
startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows

@@ -451,3 +467,7 @@ const rectRow = {

// renderer column
renderer && (text = renderer(text, index, i, row, rectRow, rectCell)) // value, index-column, index-row, row
// renderer && (text = renderer(text, index, i, row, rectRow, rectCell)) // value, index-column, index-row, row
// renderer column
if(typeof renderer === 'function'){
text = renderer(text, index, i, row, rectRow, rectCell); // value, index-column, index-row, row
}

@@ -497,4 +517,6 @@ this.text(text, posX, startY, {

// For safety, consider 3 rows margin instead of just one
if (startY + 2 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
else this.addPage();
// if (startY + 2 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
// else this.addPage();
startY + 2 * rowHeight >= maxY && this.addPage();
startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows

@@ -554,2 +576,5 @@ const rectRow = {

// add fire
this.off("pageAdded", onFirePageAdded);
return this;

@@ -556,0 +581,0 @@ }

{
"name": "pdfkit-table",
"version": "0.1.46",
"version": "0.1.47",
"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",

@@ -371,5 +371,10 @@ # pdfkit-table

### 0.1.47
+ addHeader() function on all add pages
- Thanks Anders Wasen ***@QAnders***
### 0.1.46
+ fix addBackground() function to node 8
+ addBackground() function to node 8
- Thanks ***@mehmetunubol***

@@ -376,0 +381,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc