Code Monkey home page Code Monkey logo

jspdftableplugin's Introduction

jsPdfTablePlugin

####How to use jsPdfTablePlugin

	
	/* install using bower */
	bower install jspdf-table-plugin
	
	(OR)
	Download the file  jspdf.plugin.table.js from this repository

###Docs

	height = doc.drawTable(objectArray,configObject) 
	/* both parameters are mandatory */

jsPdfTablePlugin expects an objectArray and configObject

Each key in an object in objectArray represents a column,and the 

no of rows will be equal to objectArray length.

jsPdfTablePlugin return's the current y position of Document,for further edition of Document.


ConfigObject properties xstart ,ystart,tablestart,marginright,xOffset,yOffset.

xstart      -  	horizontal starting position for table(it works as marginleft) 

tablestart  -  	vertical starting position for table in the starting page

ystart      -  	vertical starting position for table in next pages if the records exceed present page

marginright -  	this plugin uses full page width if u you wish to decrese the width of table increase 
                marginleft value

xOffset     -  	horizontal padding in cell //Optional default value 10px(don't give larger padding values)

yOffset     -  	vetrical padding in cell // Optional default value 10px(don't give larger padding values)

doc.drawTable returns current editing position.  

if the returned value is greater than  doc.internal.pageSize.height you should 
 
add a new page for further editing

u can change  the table header fill color by changing values in drawRows Method 

table plugin uses the fontSize and fontStyle set by the user

=======================================================================

Example code :-

var data = []
    ,fontSize = 12
    ,height = 0
    ,doc
    ;
	
doc = new jsPDF('p', 'pt', 'a4', true);
doc.setFont("courier", "normal");
doc.setFontSize(fontSize);
doc.text(50,100,"hi table");

function generate() {
	for (var insert = 0; insert <= 20; insert++) {
		data.push({
			"name" : "jspdf plugin",
			"version" : insert,
			"author" : "Prashanth Nelli",
			"Designation" : "AngularJs Developer"
		});
	}
	height = doc.drawTable(data, {xstart:10,ystart:10,tablestart:70,marginleft:50});
	doc.text(50, height + 20, 'hi world');
	doc.save("some-file.pdf");
};

==========================================================================

Converting table to JSON


jsPdfTablePlugin provides tableToJson method this converts the table into json array

tableToJson(id) method accepts one argument it should be an id of a table 

usage :-

var doc = new jsPDF('p','pt','a4',true);
data=doc.tableToJson(id) //returns json array

Note:- colspan feature is not supported
tableToJson method assusmes first row in the table to be the keys of the objects in jsonarray

jspdftableplugin's People

Contributors

prashanth-nelli avatar justvanbloom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.