Skip to content

Commit 40885bd

Browse files
author
Eduardo Menezes Morais
committed
Allow custom headers
1 parent 0829dc3 commit 40885bd

4 files changed

Lines changed: 51 additions & 11 deletions

File tree

dist/jspdf.amd.min.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;(function(){
2-
/** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T15:00 commit ID 278e5422ec06bbb31055b2243a1465d280a1199e )
2+
/** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T20:10 commit ID 0829dc3121ff0fee72a3e241b0c0c7a32addaff8 )
33
Copyright (c) 2010-2012 James Hall, james@snapshotmedia.co.uk, https://github.com/MrRio/jsPDF
44
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
55
MIT license.
@@ -3666,7 +3666,8 @@ API.events.push([
36663666
fontSize,
36673667
fontStyle,
36683668
padding = 3,
3669-
margin = 10,
3669+
margin = 13,
3670+
headerFunction,
36703671
lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
36713672
pages = 1,
36723673
setLastCellPosition = function (x, y, w, h, ln) {
@@ -3675,6 +3676,10 @@ API.events.push([
36753676
getLastCellPosition = function () {
36763677
return lastCellPos;
36773678
};
3679+
3680+
jsPDFAPI.setHeaderFunction = function (func) {
3681+
headerFunction = func;
3682+
};
36783683

36793684
jsPDFAPI.getTextDimensions = function (txt) {
36803685
fontName = this.internal.getFont().fontName;
@@ -3740,7 +3745,7 @@ API.events.push([
37403745

37413746

37423747
if (this.printingHeaderRow) {
3743-
this.rect(x, y, w, h, 'F');
3748+
this.rect(x, y, w, h, 'FD');
37443749
} else {
37453750
this.rect(x, y, w, h);
37463751
}
@@ -3976,6 +3981,11 @@ API.events.push([
39763981
ln;
39773982

39783983
this.printingHeaderRow = true;
3984+
if (headerFunction !== undefined) {
3985+
var position = headerFunction(this, pages);
3986+
setLastCellPosition(position[0], position[1], position[2], position[3], -1);
3987+
}
3988+
39793989
this.setFontStyle('bold');
39803990
for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
39813991
this.setFillColor(200,200,200);

dist/jspdf.min.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T15:00 commit ID 278e5422ec06bbb31055b2243a1465d280a1199e )
1+
/** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T20:10 commit ID 0829dc3121ff0fee72a3e241b0c0c7a32addaff8 )
22
Copyright (c) 2010-2012 James Hall, james@snapshotmedia.co.uk, https://github.com/MrRio/jsPDF
33
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
44
MIT license.
@@ -3665,7 +3665,8 @@ API.events.push([
36653665
fontSize,
36663666
fontStyle,
36673667
padding = 3,
3668-
margin = 10,
3668+
margin = 13,
3669+
headerFunction,
36693670
lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
36703671
pages = 1,
36713672
setLastCellPosition = function (x, y, w, h, ln) {
@@ -3674,6 +3675,10 @@ API.events.push([
36743675
getLastCellPosition = function () {
36753676
return lastCellPos;
36763677
};
3678+
3679+
jsPDFAPI.setHeaderFunction = function (func) {
3680+
headerFunction = func;
3681+
};
36773682

36783683
jsPDFAPI.getTextDimensions = function (txt) {
36793684
fontName = this.internal.getFont().fontName;
@@ -3739,7 +3744,7 @@ API.events.push([
37393744

37403745

37413746
if (this.printingHeaderRow) {
3742-
this.rect(x, y, w, h, 'F');
3747+
this.rect(x, y, w, h, 'FD');
37433748
} else {
37443749
this.rect(x, y, w, h);
37453750
}
@@ -3975,6 +3980,11 @@ API.events.push([
39753980
ln;
39763981

39773982
this.printingHeaderRow = true;
3983+
if (headerFunction !== undefined) {
3984+
var position = headerFunction(this, pages);
3985+
setLastCellPosition(position[0], position[1], position[2], position[3], -1);
3986+
}
3987+
39783988
this.setFontStyle('bold');
39793989
for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
39803990
this.setFillColor(200,200,200);

dist/jspdf.source.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T15:00 commit ID 278e5422ec06bbb31055b2243a1465d280a1199e )
1+
/** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T20:10 commit ID 0829dc3121ff0fee72a3e241b0c0c7a32addaff8 )
22
Copyright (c) 2010-2012 James Hall, james@snapshotmedia.co.uk, https://github.com/MrRio/jsPDF
33
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
44
MIT license.
@@ -3665,7 +3665,8 @@ API.events.push([
36653665
fontSize,
36663666
fontStyle,
36673667
padding = 3,
3668-
margin = 10,
3668+
margin = 13,
3669+
headerFunction,
36693670
lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
36703671
pages = 1,
36713672
setLastCellPosition = function (x, y, w, h, ln) {
@@ -3674,6 +3675,10 @@ API.events.push([
36743675
getLastCellPosition = function () {
36753676
return lastCellPos;
36763677
};
3678+
3679+
jsPDFAPI.setHeaderFunction = function (func) {
3680+
headerFunction = func;
3681+
};
36773682

36783683
jsPDFAPI.getTextDimensions = function (txt) {
36793684
fontName = this.internal.getFont().fontName;
@@ -3739,7 +3744,7 @@ API.events.push([
37393744

37403745

37413746
if (this.printingHeaderRow) {
3742-
this.rect(x, y, w, h, 'F');
3747+
this.rect(x, y, w, h, 'FD');
37433748
} else {
37443749
this.rect(x, y, w, h);
37453750
}
@@ -3975,6 +3980,11 @@ API.events.push([
39753980
ln;
39763981

39773982
this.printingHeaderRow = true;
3983+
if (headerFunction !== undefined) {
3984+
var position = headerFunction(this, pages);
3985+
setLastCellPosition(position[0], position[1], position[2], position[3], -1);
3986+
}
3987+
39783988
this.setFontStyle('bold');
39793989
for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
39803990
this.setFillColor(200,200,200);

jspdf.plugin.cell.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
fontSize,
3434
fontStyle,
3535
padding = 3,
36-
margin = 10,
36+
margin = 13,
37+
headerFunction,
3738
lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
3839
pages = 1,
3940
setLastCellPosition = function (x, y, w, h, ln) {
@@ -42,6 +43,10 @@
4243
getLastCellPosition = function () {
4344
return lastCellPos;
4445
};
46+
47+
jsPDFAPI.setHeaderFunction = function (func) {
48+
headerFunction = func;
49+
};
4550

4651
jsPDFAPI.getTextDimensions = function (txt) {
4752
fontName = this.internal.getFont().fontName;
@@ -107,7 +112,7 @@
107112

108113

109114
if (this.printingHeaderRow) {
110-
this.rect(x, y, w, h, 'F');
115+
this.rect(x, y, w, h, 'FD');
111116
} else {
112117
this.rect(x, y, w, h);
113118
}
@@ -343,6 +348,11 @@
343348
ln;
344349

345350
this.printingHeaderRow = true;
351+
if (headerFunction !== undefined) {
352+
var position = headerFunction(this, pages);
353+
setLastCellPosition(position[0], position[1], position[2], position[3], -1);
354+
}
355+
346356
this.setFontStyle('bold');
347357
for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
348358
this.setFillColor(200,200,200);

0 commit comments

Comments
 (0)