1.0.13 • Published 3 years ago

formatdata-plugin-pdfmake v1.0.13

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

formatdata-plugin-pdfmake

Format Data for PdfMake

Pdfmake is library for creating pdf file using javascript. This is a repository project for Format Data Table for PdfMake, that is generate Array from Json Format.

You can find example code in folder sample. We provide three sample javascript files for generating pdf file. We have publish this plugin in npmjs.com, you can download for your project at command prompt

Install

npm install formatdata-plugin-pdfmake

Dependencies

Examples

var fonts = {
	Roboto: {
		normal: 'node_modules/roboto-font/fonts/Roboto/roboto-regular-webfont.ttf',
		bold: 'node_modules/roboto-font/fonts/Roboto/roboto-bold-webfont.ttf',
		italics: 'node_modules/roboto-font/fonts/Roboto/roboto-italic-webfont.ttf',
		bolditalics: 'node_modules/roboto-font/fonts/Roboto/roboto-bolditalic-webfont.ttf'
	}
};


var PdfPrinter = require('pdfmake/src/printer');
var formatData = require('formatdata-plugin-pdfmake');

var printer = new PdfPrinter(fonts);
var fs = require('fs');

// SET JSON

let listJson = [
	{
		"no": "01",
		"month": "January        "
	},
	{
		"no": "02",
		"month": "Pebruary       "
	},
	{
		"no": "03",
		"month": "March          "
	},
	{
		"no": "04",
		"month": "April          "
	},
	{
		"no": "05",
		"month": "May            "
	},
	{
		"no": "06",
		"month": "June           "
	}
]


let columns = ['no', 'month',]; // column json
let styles = ['noSytle', 'monthStyle'] // column style
let columnHeaders = [{ text: 'No', style: 'headerStyle' }, { text: 'Month', style: 'headerStyle' }]; 

// style column header
let resultTable = formatData.formatTable(listJson, columns, styles, columnHeaders); 


// create array from json

var dd = {
        content: [
            {
                table: {
                    widths: [30, 60],
                    body: resultTable
                }
            }
        ],

    styles: {
        headerStyle: {
            bold: true,
            color: 'black',
            alignment: 'center'
        },
        noSytle: {
            alignment: 'center'
        },
        monthStyle: {
            alignment: 'left'
        },
        
    },
}

var pdfDoc = printer.createPdfKitDocument(dd);
pdfDoc.pipe(fs.createWriteStream('basic.pdf'));
pdfDoc.end();

API

Methods

formatData.formatTable(listJson, columns, styles, columnHeaders)

  • formatTable(< object >listJson, < array >columns, < array >styles, < object >columnHeaders] - change json data to array table format pdfmake. listJson set json data from backend. columns set columns name from json data. styles set styles for each column data. columnHeaders column's name for each header table.
1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago