pdfkit-table
Advanced tools
Comparing version 0.1.88 to 0.1.89
{ | ||
"name": "pdfkit-table", | ||
"version": "0.1.88", | ||
"version": "0.1.89", | ||
"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", |
145
README.md
@@ -54,3 +54,3 @@ <p align="center"> | ||
// the magic | ||
doc.table( table, { /* options */ }, () => { /* callback */ } ); | ||
doc.table(table, { /* options */ }, () => { /* callback */ } ); | ||
// doc.table() is a Promise to async/await function | ||
@@ -67,5 +67,8 @@ | ||
## Server response | ||
## Examples | ||
### Server response | ||
[server example](https://github.com/natancabral/pdfkit-table/blob/main/example/index-server-example.js) | ||
```js | ||
// router - Node + Express.js | ||
app.get('/create-pdf', (req, res) => { | ||
@@ -87,15 +90,20 @@ // ...table code | ||
subtitle: "Subtitle", | ||
headers: ["Country", "Conversion rate", "Trend"], | ||
headers: [ "Country", "Conversion rate", "Trend" ], | ||
rows: [ | ||
["Switzerland", "12%", "+1.12%"], | ||
["France", "67%", "-0.98%"], | ||
["England", "33%", "+4.44%"], | ||
[ "Switzerland", "12%", "+1.12%" ], | ||
[ "France", "67%", "-0.98%" ], | ||
[ "England", "33%", "+4.44%" ], | ||
], | ||
}; | ||
doc.table( table, { | ||
// A4 595.28 x 841.89 (portrait) (about width sizes) | ||
// A4 595.28 x 841.89 (portrait) (about width sizes) | ||
// width | ||
doc.table(table, { | ||
width: 300, | ||
//columnsSize: [ 200, 100, 100 ], | ||
}); | ||
// end code | ||
// or columnsSize | ||
doc.table(table, { | ||
columnsSize: [ 200, 100, 100 ], | ||
}); | ||
// done! | ||
doc.end(); | ||
``` | ||
@@ -112,8 +120,8 @@ | ||
headers: [ | ||
{ label:"Name", property: 'name', width: 60, renderer: null }, | ||
{ label:"Description", property: 'description', width: 150, renderer: null }, | ||
{ label:"Price 1", property: 'price1', width: 100, renderer: null }, | ||
{ label:"Price 2", property: 'price2', width: 100, renderer: null }, | ||
{ label:"Price 3", property: 'price3', width: 80, renderer: null }, | ||
{ label:"Price 4", property: 'price4', width: 43, | ||
{ label: "Name", property: 'name', width: 60, renderer: null }, | ||
{ label: "Description", property: 'description', width: 150, renderer: null }, | ||
{ label: "Price 1", property: 'price1', width: 100, renderer: null }, | ||
{ label: "Price 2", property: 'price2', width: 100, renderer: null }, | ||
{ label: "Price 3", property: 'price3', width: 80, renderer: null }, | ||
{ label: "Price 4", property: 'price4', width: 43, | ||
renderer: (value, indexColumn, indexRow, row) => { return `U$ ${Number(value).toFixed(2)}` } | ||
@@ -158,3 +166,3 @@ }, | ||
}; | ||
// the magic | ||
doc.table(table, { | ||
@@ -167,2 +175,5 @@ prepareHeader: () => doc.font("Helvetica-Bold").fontSize(8), | ||
}); | ||
// done! | ||
doc.end(); | ||
``` | ||
@@ -173,24 +184,27 @@ | ||
```js | ||
// renderer function inside json file | ||
const tableJson = '{ | ||
"headers": [ | ||
{ "label":"Name", "property":"name", "width":100 }, | ||
{ "label":"Age", "property":"age", "width":100 }, | ||
{ "label":"Year", "property":"year", "width":100 } | ||
], | ||
"datas": [ | ||
{ "name":"bold:Name 1", "age":"Age 1", "year":"Year 1" }, | ||
{ "name":"Name 2", "age":"Age 2", "year":"Year 2" }, | ||
{ "name":"Name 3", "age":"Age 3", "year":"Year 3", | ||
"renderer": "function(value, i, irow){ return value + `(${(1+irow)})`; }" | ||
// renderer function inside json file | ||
const tableJson = '{ | ||
"headers": [ | ||
{ "label":"Name", "property":"name", "width":100 }, | ||
{ "label":"Age", "property":"age", "width":100 }, | ||
{ "label":"Year", "property":"year", "width":100 } | ||
], | ||
"datas": [ | ||
{ "name":"bold:Name 1", "age":"Age 1", "year":"Year 1" }, | ||
{ "name":"Name 2", "age":"Age 2", "year":"Year 2" }, | ||
{ "name":"Name 3", "age":"Age 3", "year":"Year 3", | ||
"renderer": "function(value, i, irow){ return value + `(${(1+irow)})`; }" | ||
} | ||
], | ||
"rows": [ | ||
[ "Name 4", "Age 4", "Year 4" ] | ||
], | ||
"options": { | ||
"width": 300 | ||
} | ||
], | ||
"rows": [ | ||
["Name 4", "Age 4", "Year 4"] | ||
], | ||
"options": { | ||
"width": 300 | ||
} | ||
}'; | ||
doc.table( tableJson ); | ||
}'; | ||
// the magic | ||
doc.table(tableJson); | ||
// done! | ||
doc.end(); | ||
``` | ||
@@ -202,11 +216,37 @@ | ||
```js | ||
const json = require('./table.json'); | ||
// if json file is array | ||
Array.isArray(json) ? | ||
// any tables | ||
json.forEach( table => doc.table( table, table.options || {} ) ) : | ||
// one table | ||
doc.table( json, json.options || {} ) ; | ||
const json = require('./table.json'); | ||
// if json file is array | ||
Array.isArray(json) ? | ||
// any tables | ||
json.forEach(table => doc.table(table, table.options || {})) : | ||
// one table | ||
doc.table(json, json.options || {}) ; | ||
// done! | ||
doc.end(); | ||
``` | ||
### Example 5 - Promise async/await | ||
```js | ||
// async | ||
;(async function(){ | ||
// table | ||
const table = { | ||
title: "Title", | ||
subtitle: "Subtitle", | ||
headers: ["Name", "Age"], | ||
rows: [ | ||
["Jack", "20"], | ||
["Johnson", "30"], | ||
], | ||
}; | ||
// await | ||
await doc.table(table) ; | ||
// done! | ||
doc.end(); | ||
})(); | ||
``` | ||
## Table | ||
@@ -229,4 +269,4 @@ | ||
- rows <code>Array.[]</code> | ||
- title <code>String</code> | ||
- subtitle <code>String</code> | ||
- title <code>String</code> | <code>Object</code> | ||
- subtitle <code>String</code> | <code>Object</code> | ||
@@ -305,3 +345,2 @@ ### Headers | ||
#### Options example | ||
@@ -318,7 +357,8 @@ | ||
divider: { | ||
header: {disabled: false, width: 2, opacity: 1}, | ||
horizontal: {disabled: false, width: 0.5, opacity: 0.5}, | ||
header: { disabled: false, width: 2, opacity: 1 }, | ||
horizontal: { disabled: false, width: 0.5, opacity: 0.5 }, | ||
}, | ||
padding: 5, // {Number} default: 0 | ||
columnSpacing: 5, // {Number} default: 5 | ||
hideHeader: false, | ||
// functions | ||
@@ -422,2 +462,7 @@ prepareHeader: () => doc.font("Helvetica-Bold").fontSize(8), // {Function} | ||
### 0.1.86 | ||
- TypeScript (ts) interface (index.ts) | ||
- Thanks Côte Arthur ***@CoteArthur*** | ||
### 0.1.83 | ||
@@ -424,0 +469,0 @@ |
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
54063
677